A quick code snippet to send email using VB.Net, works fine
in VS 2010.
my_email_address@myEmail.com - this is the email account
that will be used to send out email
My_SimplE_PassW@rd - password of the email account that is
used to send out the email
my_recipient@Recipient_email.com - the recipient of the
email or the person who will receive the email
SmtpServer.Port = 25 – change this port number if the email
server blocks port 25
SmtpServer.Host = "mail.my_server_name" – change to
the email server name or ask your email administrator
Try
Dim
SmtpServer As New SmtpClient()
Dim mail
As New MailMessage()
SmtpServer.Credentials = New _
Net.NetworkCredential("my_email_address@myEmail.com",
"My_SimplE_PassW@rd")
SmtpServer.Port = 25
SmtpServer.Host = "mail.my_server_name"
mail = New
MailMessage()
mail.From
= New MailAddress("my_email_address@myEmail.com")
mail.To.Add("my_recipient@Recipient_email.com")
mail.Subject = "My Email Subject: "
mail.Body
= "write the body of email here - this is my message"
SmtpServer.Send(mail)
MsgBox("mail send")
Catch ex As
Exception
MsgBox(ex.ToString)
End Try
Comments
Post a Comment