Tuesday 6 December 2011

Send email with attachment through windows application


Imports System.Net
Imports System.Net.Mail


 1. Using your Gmail Account

Dim MyMailMessage As New System.Net.Mail.MailMessage(Sender's email address, Receiver's email address, Subject, msg)
MyMailMessage.IsBodyHtml = False
Dim attach As New System.Net.Mail.Attachment(path of filename)
MyMailMessage.Attachments.Add(attach)
Dim mailAuthentication As New NetworkCredential(Sender's email Address, Sender's Password)
Dim mailClient As New System.Net.Mail.SmtpClient("smtp.gmail.com", 587)
mailClient.EnableSsl = True
mailClient.UseDefaultCredentials = False
mailClient.Credentials = mailAuthentication
mailClient.Send(MyMailMessage)
MyMailMessage.Attachments.Dispose()

2. From your yahoo Account

Replace the following lines on the above code

Dim mailClient As New System.Net.Mail.SmtpClient("smtp.gmail.com", 587)
mailClient.EnableSsl = True

with

Dim mailClient As New System.Net.Mail.SmtpClient("smtp.mail.yahoo.com", 25)
mailClient.EnableSsl = False

No comments:

Post a Comment