There was a problem loading the comments.

Sending mail from Classic ASP

Support Portal  »  Knowledgebase  »  Viewing Article

  • 31 December 1969 6:00 PM

You can use the below code (by making required configuration changes) for sending out emails using SMTP authentication through Classic ASP: 

<%    Dim intError    Dim strResult 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   Session("ErrDescription")=Err.Description End Function intError = SendMail("your-mailserver-ip", "", "smtp-password", "send-from-email", "send-to-email", "send-cc-email", "send-bcc-email", "email-subject", "text", "email-body") If intError = 0 Then    'No errors, mail sent    strResult = "The mail has been sent successfully." Else    strResult = "There was a problem sending the mail" End if Response.Write(strResult) %>

Share via
Did you find this article useful?  

Related Articles

© Softsys Hosting