Simple ASP.net Send Email Subroutine

BluJag

Perch
17 March 2007

Tested in asp.net version 1 (see next post for verson 2) Neither tried with an AOL address yet - will be interested to hear if it works OK.

Dim MyMail As New System.Web.Mail.MailMessage
Dim SMTP As System.Web.Mail.SmtpMail

Dim Email as string
Dim Subject as string
Dim MsgTxt as string

With MyMail

.To = Email
.From = "[email protected]"
.Subject = Subject
.Body = MsgTxt
.Bcc = "[email protected]"
.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.domain.com"
.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]"
.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

End With


With SMTP
.SmtpServer = "mail.domain.com"
.Send(MyMail)
End With
 
Tested in asp.net version 2

Dim Credential As New System.Net.NetworkCredential("[email protected]", "password")

Dim MyMail As New System.Net.Mail.MailMessage

Dim Client As New System.Net.Mail.SmtpClient()

Client.Host = "mail.domain.com"


Client.Credentials = Credential

Dim Email As New System.Net.Mail.MailMessage
With Email
.From = New System.Net.Mail.MailAddress("[email protected]")
.To.Add("[email protected]")
.CC.Add("[email protected]")
.Bcc.Add("[email protected]")
.ReplyTo = New System.Net.Mail.MailAddress("[email protected]")
.Subject = "Your subject"
.IsBodyHtml = False
.Body = "Your message text etc"


End With

Try

Client.Send(Email)

Catch ex As Exception
'some processing code here to handle errors
End Try
 
Back
Top