Friday, July 27, 2007

Insert image in Html mail using .Net

I guess, we all are habituated with E-Mails. Sometimes we need to transfer more information in E-Mails so we attach files, presentations, images etc. and when we need it to be more attractive and colorful then we try our hand with Html for making more colorful and attractive and insert images as necessary to make it more meaningful.

When we need to build this type of actions in our application, then we search for related Components and Libraries to get support from. So let's discuss about .Net supported libraries to achieve this type of action in our application. In this article we will cover the System.Net.Mail Namespace of System.dll in .Net Framework 2.0 to build a mailing application.


Now we are going to build a Service or Application that will Send Mail with some interesting features like; body content in html format, send to multiple recipients, send mail with attachment(s), to make it more meaningful send Html mail with Images Embedded in it, send html mail with embedded images and attachments, mail with multipart bodies etc..

A simple Html mail:

Let's check a mail message created by System.Net.Mail.MailMessage to send a mail...

The codes are:

Sample for Html mail:


Public Sub SendHtmlMail()

'create the mail message

Dim mail As New MailMessage("from@fromdomain.com", "to@todomain.com")

'set the message content

mail.Subject = "This mail has Html Body.."

mail.Body = "This is a sample body with html in it. This is bold This is blue"

mail.IsBodyHtml = True

'send mail

SendMail(mail)

End Sub ' End SendHtmlMail


Private Sub SendMail(ByVal mail As Mail.MailMessage)

'send the message using SMTP client

Dim smtp As New SmtpClient(_mailServer) 'mail Server IP or NAME

smtp.Credentials = CredentialCache.DefaultNetworkCredentials

smtp.Send(Mail)

End Sub ' End SendMail


Here "mail" is the instance of MailMessage Class. There are four overloaded constructors available initializing different properties of MailMessage Class during making instance.........



For more details please visit : http://aspalliance.com/1354_Sending_HTML_Mail_with_Embedded_Image_in_NET



Thanks,

Soyuj Kumar...Coffee Drinker

2 comments:

Pooja Mahimkar said...

that was informative, and thanks for commenting on my blog, its always welcomed :)

Inheritx Solutions said...

Thanks a lot for that fantastically amazing post!

Ruby on Rails Development | Asp.net Development