Search our database

How to send mail using ASP?

To send a message from your domain via ASP, here is a sample code. Assume that:

Domain name: abc.com.my
Mail server Host-name: mail.abc.com.my
E-mail account: user1@abc.com.my
password: pass4567

<%
Dim objMessage
 
Set objMessage = Server.CreateObject("CDO.Message")
 
With objMessage.Configuration.Fields
  'Send the message using the network (SMTP over the network).
  .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") 
     = "mail.abc.com.my"
  .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 2525
  'Use SSL for the connection (True or False)
  .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
  .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
 
  'Type of authentication, NONE, Basic (Base64 encoded), NTLM
  .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
  .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") 
     = "user1@abc.com.my"
  .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "pass4567"
  .Update
End With
 
With objMessage
  .To = "Recipient Name "
  .From = "Sender Name"
  .Subject = "This is the mail subject"
  .TextBody = "This is the mail message."
  .Send
End With
 
Set objMessage = Nothing
 
Response.Write "Message sent!"
%>

Tags: ,