Need example in VB2005 code for sending Emails with images!

Heavenly

Well-known member
Joined
Aug 22, 2005
Messages
53
Location
Puerto Rico
Programming Experience
1-3
Please post any link you might think will help me understand and develop a small application for sending emails containing an image not as an attachment but instead images placed along with the text.

If this cannot be done then I will settle for having the Image as an attachment. I’m only interested in Sending; I’m not interested in receiving Emails.

Thanks ALL
 
This is what I got so far:


VB.NET:
[SIZE=2][COLOR=#0000ff]
Imports[/COLOR][/SIZE][SIZE=2] System.Net.Mail.MailMessage
[/SIZE][SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Web.Mail
[/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] FormSendEmails
[/SIZE][SIZE=2][COLOR=#008000]'// Specify the file to be attached and sent.
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]' // This example assumes that a file named Data.xls exists in the
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]' // current working directory.
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Shared[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] CreateMessageWithAttachment([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] server [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] file [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"ImageAttach.jpg"
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'// Create a message and set up the recipients.
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] EmailToAddress [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Net.Mail.MailAddress([/SIZE][SIZE=2][COLOR=#800000]"rosa@telemetrika.com"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] EmailMessage [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Net.Mail.MailMessage = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Net.Mail.MailMessage()
[/SIZE][SIZE=2][COLOR=#008000]'// Create the file attachment for this e-mail message.
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] EmailAttachment [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Net.Mail.Attachment = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Net.Mail.Attachment(file, System.Net.Mime.MediaTypeNames.Application.Octet)
EmailMessage.To.Add(EmailToAddress)
EmailMessage.From = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Net.Mail.MailAddress([/SIZE][SIZE=2][COLOR=#800000]"anibal@telemetrika.com"[/COLOR][/SIZE][SIZE=2])
EmailMessage.Subject = [/SIZE][SIZE=2][COLOR=#800000]"See my new HMI attached"
[/COLOR][/SIZE][SIZE=2]EmailMessage.Body = [/SIZE][SIZE=2][COLOR=#800000]"I just wanted you to see my new HMI developed using VB2005"
[/COLOR][/SIZE][SIZE=2]EmailMessage.Attachments.Add(EmailAttachment)
[/SIZE][SIZE=2][COLOR=#008000]'// Add time stamp information for the file.
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] disposition [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Net.Mime.ContentDisposition = EmailAttachment.ContentDisposition
disposition.CreationDate = System.IO.File.GetCreationTime(file)
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file)
disposition.ReadDate = System.IO.File.GetLastAccessTime(file)
[/SIZE][SIZE=2][COLOR=#008000]'// Add credentials if the SMTP server requires them.
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] client [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Net.Mail.SmtpClient = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Net.Mail.SmtpClient([/SIZE][SIZE=2][COLOR=#800000]"smtp.bizmail.yahoo.com"[/COLOR][/SIZE][SIZE=2])
client.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials
client.Send(EmailMessage)
 
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] ButtonSendEmail_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] ButtonSendEmail.Click
CreateMessageWithAttachment([/SIZE][SIZE=2][COLOR=#800000]"smtp.bizmail.yahoo.com"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]


I'm getting this error:
'Syntax error, command unrecognized. The server response was: yahoo.com closing transmission channel. You must be pop-authenticated before you can use this smtp server, and you must use your yahoo mail address for the Sender/From field.



Question:

Do I need to code my password and user name for authentication?, If so where?
 
Back
Top