» Host multiple domains in one plan
» Manage all your domains in one control panel
» Both Windows and Linux Options
» Windows Plans starting at .95 per month
» Linux Plans starting at .95 per month
» Windows Plan: MS SQL 2005 Database Included
 
Window Plans   Linux Plans
 
Close  
Accu Web Hosting Accu Web Hosting Accuweb Hosting
Accu Web Hosting Accu Web Hosting Window Hosting Home Accu Web Hosting Window Hosting Accu Web Hosting PHP Hosting Accu Web Hosting Reseller Accu Web Hosting SQL Hosting Accu Web Hosting   accu web hosting
 

Go Back   Web Hosting Technical Support Discussion Forum > General Web Hosting Discussion Forum and Support > Windows Web Hosting Discussion Forum

Windows Web Hosting Discussion Forum Discussion Forum on Windows Web Hosting Related Support Issues. Discuss your Issues related to ASP.NET, MS SQL, ASP, DLL, Components, etc...

Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old 08-02-2005
Member
 
Join Date: Aug 2004
Posts: 65
Rep Power: 0
Vaughn is on a distinguished road
Send a message via MSN to Vaughn Send a message via Yahoo to Vaughn
Default

How to send Emails via ASP using SMTP Authentication

There are several ways through which emails can be sent via ASP. The method which I am going to demonstrate will use CDOSYS and will use SMTP authentication. Secondly, I will encapsulate the code in a general function so that it can be used in any of your ASP pages by just including this file. The salient features of the code which I have demonstrated are:

1) Usage of a function, thus expanding portability.
2) Optional usage of fields like 'Cc' and 'Bcc' as per the senders discretion.
3) The sender can skip the 'From' email address if it is same as the SMTP user.
4) The sender can decide whether the content of the mail is to be send in text or html format.
5) After the mail is sent, an error number, if any, is returned. Thus, the sender can write proper error handling code, if required.

So let's begin!

A. Implementation

1) Create a file called 'EMail.asp', or you can choose any other name as per your preference.
2) Paste the below code into it:

Code:
<!--
 Â* Â*METADATA
 Â* Â*TYPE="typelib"
 Â* Â*UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"
 Â* Â*NAME="CDO for Windows 2000 Library"
-->
<%
Function SendMail(SMTPServer, SMTPUserName, SMTPPassword, EMailFrom, EMailTo, EMailCc, EMailBcc, EMailSubject, EMailType, EMailContent)
 Â* Â*Dim cdoConfig
 Â* Â*Dim cdoMessage
 Â* Â*Dim intErr
 Â* Â*
 Â* Â*Set cdoConfig = CreateObject("CDO.Configuration")
 Â* Â*With cdoConfig.Fields
 Â* Â* Â* Â* .Item(cdoSendUsingMethod) = cdoSendUsingPort
 Â* Â* Â* Â* .Item(cdoSMTPServer) = SMTPServer
 Â* Â* Â* Â* .Item(cdoSMTPAuthenticate) = 1
 Â* Â* Â* Â* .Item(cdoSendUsername) = SMTPUserName
 Â* Â* Â* Â* .Item(cdoSendPassword) = SMTPPassword
 Â* Â* Â* Â* .Update
 Â* Â*End With
 Â* 
 Â* Â*Set cdoMessage = CreateObject("CDO.Message")
 Â* Â*With cdoMessage
 Â* Â* Â* Â* Set .Configuration = cdoConfig
 Â* Â* Â* Â* If Len(Trim(CStr(EMailFrom))) = 0 Then
 Â* Â* Â* Â* Â* Â* Â*.From = SMTPUserName
 Â* Â* Â* Â* Else
 Â* Â* Â* Â* Â* Â* Â*.From = EMailFrom
 Â* Â* Â* Â* End If
 Â* Â* Â* Â* .To = EMailTo
 Â* Â* Â* Â* If Len(Trim(CStr(EMailCc))) <> 0 Then .Cc = EMailCc
 Â* Â* Â* Â* If Len(Trim(CStr(EMailBcc))) <> 0 Then .Bcc = EMailBcc
 Â* Â* Â* Â* .Subject = EmailSubject
 Â* Â* Â* Â* If EMailType = "text" Then
 Â* Â* Â* Â* Â* Â* Â*.TextBody = EMailContent
 Â* Â* Â* Â* ElseIf EMailType = "html" Then
 Â* Â* Â* Â* Â* Â* Â*.HTMLBody = EMailContent
 Â* Â* Â* Â* End If
 Â* Â* Â* Â* .Send

 Â* Â* Â* Â* intErr = Err.Number
 Â* End With

 Â* Set cdoMessage = Nothing
 Â* Set cdoConfig = Nothing

 Â* SendMail = intErr
End Function
%>
Alternatively, you can download the file from here.

3) Save the file. You're done!

B. Usage

Using this function is extremely simple and just a matter of including the above file and calling the function. Let's take an example where you have to send mails from an ASP file called 'MailMembers.asp'. Follow the below steps to implement this:

1) Move the 'EMail.asp' in your 'includes' directory. Typically this directory is called 'includes' itself, personally I use that name for the sake of convenience.
2) Open the ASP file, in our case it would be 'MailMembers.asp'.
3) Scroll to the top and insert the below line at the top of the page, but below the '@Language' or 'Option Explicit' or any other directives, if you are using them:

Code:
<%@Language=VBScript%>
<% Option Explicit %>
<!-- #include virtual = "/Includes/Email.asp" -->
'Other Include files follows...
-----------------
-----------------
-----------------
'Your regular ASP code follows...
<%
-----------------
-----------------
-----------------
%>
4) Finally call the 'SendMail' at the point in your code where you need to send the mail. The below example demonstrates error trapping as well:

Code:
<%
'Declare Variables
Dim intError
Dim strResult

intError = SendMail("mail.mydomainname.com", "mail@mydomainname.com", "mypass", "admin@mydomainname.com", "john@accuwebhosting.com", "", "", "New membership!", "text", "Welcome to our club!")
If intError = 0 Then
 Â* Â*'No errors, mail sent
 Â* Â*strResult = "The mail has been sent successfully"
Else
 Â* Â*strResult = "There was a problem sending the mail"
 Â* Â*'Error Handling code follows
 Â* Â*-----------------
 Â* Â*-----------------
 Â* Â*-----------------
End If

'Inform the user
Response.Write(strResult)
%>
That's it! Happy mailing.

Your comments and/or suggestions are welcome.

Cheers!
__________________
Vaughn
Team Leader // Tech. Support
AccuWebHosting.Com
email:support@accuwebhosting.com

Blog: blogsandbloggers.com/Vaughn
http://www.accuwebhosting.biz/Vaughn...aughn_Sign.jpg
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 09-12-2005
Junior Member
 
Join Date: Sep 2005
Posts: 1
Rep Power: 0
edgardg is on a distinguished road
Default

I have a database with emails.
For these, I am curently sending mails manually. In other words, I send it to myself and then on the bcc I put the address of those I'm sending the emails.
Since there are so many, I have to break it down in 3 or 4 times.

I want to be able to get them all in a database( that would be easy) and then from the database send emails automatically to each one.
My database should be on the hosting service machine.

How do I do this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-20-2005
Member
 
Join Date: Aug 2004
Posts: 65
Rep Power: 0
Vaughn is on a distinguished road
Send a message via MSN to Vaughn Send a message via Yahoo to Vaughn
Default

Quote:
Originally posted by edgardg@Sep 12 2005, 08:59 PM
I have a database with emails.
For these, I am curently sending mails manually. In other words, I send it to myself and then on the bcc I put the address of those I'm sending the emails.
Since there are so many, I have to break it down in 3 or 4 times.

I want to be able to get them all in a database( that would be easy) and then from the database send emails automatically to each one.
My database should be on the hosting service machine.

How do I do this?
Hi Edgardg,

Sorry for the delay in reply. Below are the rough guidelines to accomplish what you want, which I believe are very straightforward:

Note: You will need some coding experience with ASP.

1) Create an access database. If you are hosting on AccuWebHosting servers then you know that it's easy to create one through your control panel and best of all, it's free.
2) Next, create a table that stores the information, for example the names and email addresses.
3) Next, write an ASP page that does the below:
a. Connects to the database.
b. Has a loop that iterates through the Recordset (Table) that has the Name and email addresses from the beginning of the Recordset to the end.
c. Finally, simply call the mailing function that I have written to send mails in each iteration of your loop.
__________________
Vaughn
Team Leader // Tech. Support
AccuWebHosting.Com
email:support@accuwebhosting.com

Blog: blogsandbloggers.com/Vaughn
http://www.accuwebhosting.biz/Vaughn...aughn_Sign.jpg
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-18-2005
Member
 
Join Date: Aug 2004
Posts: 65
Rep Power: 0
Vaughn is on a distinguished road
Send a message via MSN to Vaughn Send a message via Yahoo to Vaughn
Default

Vijay,

What you can do is create an ASP page that sends the emails and then request us to schedule the asp page at time intervals which you need. After this is done, the system will automatically call the ASP page at the scheduled times, resulting in the code being executed in the page.

Thanks,
__________________
Vaughn
Team Leader // Tech. Support
AccuWebHosting.Com
email:support@accuwebhosting.com

Blog: blogsandbloggers.com/Vaughn
http://www.accuwebhosting.biz/Vaughn...aughn_Sign.jpg
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to configure SMTP for my domain eluceon Windows Web Hosting Discussion Forum 1 07-28-2006 06:24 PM
Prevent the IIS SMTP Virtual Server from Relaying E-mail Messages Manuel_ Windows Dedicated Servers 0 06-22-2006 04:36 PM
Fraudent Emails sent under our address Cynthia E Recent Issues & Updates 1 11-12-2005 12:46 AM
How to use the SMTP server anand Windows Web Hosting Discussion Forum 1 07-03-2005 06:46 PM


All times are GMT -5. The time now is 12:24 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC5
http://www.accuwebhosting.com/terms.htm

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32