Emailing from Classic ASP


The following function covers emailing from ASP:

Function sendMail (strTo, strFrom, strSubject, strMessage)

 strFormat = “<style>” & vbcrlf & “body{font-family:Arial, Helvetica, sans-serif;font-size:10pt;}” & vbcrlf & “</style>”

 sch = “

    Set cdoConfig = CreateObject(“CDO.Configuration”)

    With cdoConfig.Fields
        .Item(sch & “sendusing”) = 2 ‘ cdoSendUsingPort
        .Item(sch & “smtpserver”) = “Enter your email server IP here
  .Item(sch & “smtpauthenticate”) = 1 ‘cdoBasic
        .Item(sch & “sendusername”) = “Enter your mailbox user here e.g. mail (which maps to – you don’t need the domain)”
        .Item(sch & “sendpassword”) = “Enter your mailbox password here
    End With

    Set cdoMessage = CreateObject(“CDO.Message”)

 On Error Resume Next

 With cdoMessage
        Set .Configuration = cdoConfig
  .To = strTo
        .From = strFrom
        .Subject = strSubject
  ‘.TextBody = strMessage
  .HTMLBody  = strFormat & strMessage
    End With

  ‘Response.Write strMessage

 If err.Number <> 0 Then
  SendMail = False
  Response.Write err.Number
  SendMail = True
 End If

    Set cdoMessage = Nothing
    Set cdoConfig = Nothing

End Function

And here is an example calling this function:

 x=sendMail (“”, “Reports”, “A test report”, “Test email”)

This will send an email with ‘Test email’ as the body, ‘A test report’ as the subject line, ‘Reports’ as the from address, ‘’ as the To address.

x is true if all ok, false if an error occurred.

Happy emailing!

Author: James

IT Manager - Network, Web coding, MS SQL and Online Mapping expert

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s