Saturday, June 26, 2010

Sending email from asp.net

These are very basic step needed to send email from asp.net. I am here not explaining error handling and attachment in mail message.Make sure to import system.net.mail namespace

Dim XMail As New MailMessage ‘Declare a mail object
Dim XSmtp As New SmtpClient ‘declare object of Smtp client

‘Set mail from
XMail.From = New MailAddress("xyzfrom@domain.com", "From display name")
‘set mail to, here we can add multiple addresses

XMail.To.Add("xyzto@domain.com")
‘set cc for mail message, in the same way we can set name in to also
XMail.CC.Add(New MailAddress("xyzcc@domain.com", "cc display name"))
XMail.Subject = "email subject"
XMail.Body = "email body"
‘host will provide you email service provider
XSmtp.Host = "mail.domain.com"
‘credentials will be your email address and password
XSmtp.Credentials = New System.Net.NetworkCredential("xyzfrom@domain.com", "password")
‘send email
XSmtp.Send(XMail)

No comments:

Post a Comment