Jan 31 2006

ASPMail ( SMTPsvg.Mailer )

Posted by admin under Generic sendmail

Function SendEmail( sEmailServer, sFromEmail, sToEmail, sSubject, sText )
   Dim objMail
   set objMail = server.createobject("SMTPsvg.Mailer")
   objMail.FromName = sFromEmail
   objMail.FromAddress = sFromEmail
   objMail.RemoteHost = sEmailServer
   objMail.AddRecipient sToEmail, sToEmail
   objMail.Subject = sSubject
   objMail.BodyText = sText
   if objMail.SendMail then
     SendEmail = ""
   else
      ' Message send failure
      SendEmail = objMail.Response
   end if
   Set objMail = nothing
End Function
 
1. Copy it into a file called incgenmail.asp

2. Include that file from your ASP page supposed to send the mail
<!--#include file="incgenmail.asp"-->


3. Call it like this:
sErrMsg = SendEmail( "smtp.theserver.com",  
           "webmaster@aspcode.net", 
           "John@doe.com", 
           "Important message", 
           "This is an important message bla bla" ) 


4. You can check sErrMsg. If it is "" then mail was sent ok, otherwise there was an error and sErrMsg contains an descriptive text of it.

Links