Friday, November 23, 2007

Nose Bleed Every Morning



Hello

Something that is very interesting and useful is to add to your applications the ability to send emails, so I pass the code that uses a Gmail account to make mailings, the advantage of using gmail is always available because it is free lol, the only care to be taken is to indicate the port right and send SMTP SSL, well there goes the code.

1. Include the following in the source file

Imports System.Net.Mail

2. The code for sending via gmail goes like

'First we set the Parameters to send to gmail

Dim As oSmtp SmtpClient = New SmtpClient
New oSmtp.Credentials = System.Net. NetworkCredential ( "MiCuenta@gmail.com" , "ElSuperPassw" )
oSmtp.Port = 587 'Gmail needs a specific port
oSmtp.Host = "smtp.gmail.com"
oSmtp.EnableSsl = True 'Gmail need to send by SSL

Dim As oMail MailMessage = New MailMessage
oMail.To.Add ( destino1@gmail.com )
oMail.To.Add ( destino2@gmail.com )
oMail.From = New MailAddress ( "MiCuenta@gmail.com" , ", System.Text.Encoding.UTF8)
oMail.Subject = "This mail is ...."

oMail.SubjectEncoding = System.Text.Encoding.UTF8

'----

creation of the post Dim

s As New System.Text.StringBuilder

s.Append( "bla bla bla bla" & vbCrLf)
s.Append( "bla bla bla bla" & vbCrLf)
s.Append( "bla bla bla bla" & vbCrLf)

oMail.Body = s.ToString

oMail.BodyEncoding = System.Text.Encoding.UTF8
oMail.IsBodyHtml = False

Try
oSmtp.Send(oMail)

Catch ex As System.Net.Mail.SmtpException
msgbox "Error " & ex.Message

End Try

Well that's it, I hope they serve,

Salu2
Sergio

0 comments:

Post a Comment