Windows Phone Developers

Tuesday, May 6, 2008

Create Mail in Vb.Net with attachments

Automatically send a mail with attachment using VB.NET

Imports System.Net.Mail

Imports System.Net.Mime

Imports System.ComponentModel

Sub CreateMail_With_Attachment()

Dim oMailMsg As New MailMessage

Dim oMailClient As SmtpClient

oMailMsg.From = New MailAddress("info@vbadud.com")

oMailMsg.To.Add(New MailAddress("admin@vbadud.com", "Administrator"))

oMailMsg.Body = "Attached Sample Document for processing."

oMailMsg.Subject = "Sample Mail"

oMailMsg.Attachments.Add(New Attachment("C:\temp\sample.doc"))

oMailClient = New SmtpClient("smtp.vbadud.com")

oMailClient.Send(oMailMsg)

End Sub

The Attachment class is used with the MailMessage class. All messages include a Body, which contains the content of the message. In addition to the body, you might want to send additional files. These are sent as attachments and are represented as Attachment instances. To add an attachment to a mail message, add it to the MailMessage..::.Attachments collection.

Attachment content can be a String, Stream, or file name. You can specify the content in an attachment by using any of the Attachment constructors.

The MIME Content-Type header information for the attachment is represented by the ContentType property. The Content-Type header specifies the media type and subtype and any associated parameters. Use ContentType to get the instance associated with an attachment.

The MIME Content-Disposition header is represented by the ContentDisposition property. The Content-Disposition header specifies the presentation and file time stamps for an attachment. A Content-Disposition header is sent only if the attachment is a file. Use the ContentDisposition property to get the instance associated with an attachment.

The MIME Content-Transfer-Encoding header is represented by the TransferEncoding property.

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment

kbAlertz.com :: Visual Studio 2005

kbAlertz.com :: Visual Studio 2008

kbAlertz.com :: Visual Basic 2005