Mohammed Atef’s Technical blog

Send Email with attachment file

With the few line of codes you can send an e-Mail with attachment file. via .net application

Dim data As New Attachment(strFileName, System.Net.Mime.MediaTypeNames.Application.Octet)

‘Add time stamp information for the file.

Dim disposition As System.Net.Mime.ContentDisposition

disposition = data.ContentDisposition

disposition.CreationDate = System.IO.File.GetCreationTime(strFileName)

disposition.ModificationDate = System.IO.File.GetLastWriteTime(strFileName)

disposition.ReadDate = System.IO.File.GetLastAccessTime(strFileName)

‘ Add the file attachment to this e-mail message.

myMessage.Attachments.Add(data)

myMessage.Priority = MailPriority.High

‘Send the message.

Dim client As New System.Net.Mail.SmtpClient(“10.0.0.27″)

‘Add credentials if the SMTP server requires them.

client.Credentials = New System.Net.NetworkCredential(“matef”, “123″)

client.Send(myMessage)

 

February 8, 2009 Posted by | Asp.net, C#,VB.Net, Developement | | Leave a Comment

   

Follow

Get every new post delivered to your Inbox.