Click here to Skip to main content
14,355,411 members

(ASP.NET)Sending mail using SMTP in HTML format using IP settings in web.config file

Rate this:
1.79 (12 votes)
Please Sign up or sign in to vote.
1.79 (12 votes)
20 Feb 2006
This article briefs you about sending mail using SMTP in HTML Format, which takes the default SMTP settings from web.config file


This articles educates you to send mails using SMTP mail server in HTML format. It makes use of default settings from the web.config for sending e-mail.

Source Code

How to set the value in web.config
open the web.config fine either in a VS.NET editor or using anyother text editor.

Add the below code between the <appSettings> Add the below with your IP  </appSettings> tags. Your resultant code looks like this


<add key="SmtpServer" value="<Your SMTP IP>"/>



Adding code to the form
Open an application in ASP.NET. Add a button to the web form with the name SendClick

Paste the below code on the button click event

Private Sub SendClick()
        Dim mailMsg As New MailMessage
            mailMsg.To = "<tomailid>"
            mailMsg.From = "<frommailid>"
            'mailMsg.BodyFormat = MailFormat.Text 'optional for sending text in body
            mailMsg.BodyFormat = MailFormat.Html
            mailMsg.Subject = "Statistics Report"
            mailMsg.Body = "<html><body><Table><tr><td>Hi,</td></tr><tr><td>Details of the Statistics :</td></tr></Table></body></html><html><body>" & "sometext" & _
            "</body></html><html><body><Table><tr><td> </td></tr><tr><td>NOTE: This is an automated mail. Please, do not reply.</td></tr>" & _
            "<tr><td>*Green coloured rows indicates temporary demos</td></tr>" & _
            "<tr><td>**All statistics are based on the page naming conventions Eg., 22_10_2005_</td></tr>" & _
            "<tr><td> </td></tr><tr><td>Regards,</td></tr><tr><td>some text,</td></tr><tr><td>some text,</td></tr>" & _
            "<tr><td> Some text </td></tr></table></body></html>" 
            SmtpMail.SmtpServer = ConfigurationSettings.AppSettings("SmtpServer")
            'xm.InnerHtml = "Your message has been sent"
        Catch ex As Exception
        End Try
    End Sub

In the above code 'mailMsg' is the name of the object of type MailMessage. We are using this object to set the 'To' address, 'From' address, 'BodyFormat' etc.

We are setting the body format tag to 'MailFormat.HTML' as the body format is of type HTML. We can use 'MailFormat.Text' for the text format. 'Subject' for setting the subject as well as for 'CC' and 'BCC'.

SmtpMail.SmtpServer = ConfigurationSettings.AppSettings("SmtpServer")

In the above line we are setting the ip to the object.

Configurations.AppSettings("SmtpServer") will read the value from the web.config and assigns it dynamically.

The above line of code will send the mail......

Happy Mailing..... :)





This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States
No Biography provided

Comments and Discussions

Questionhow to create mail address box? Pin
duraie20-Mar-08 0:33
memberduraie20-Mar-08 0:33 
AnswerRe: how to create mail address box? Pin
Abhijat Chauhan7-May-11 0:59
memberAbhijat Chauhan7-May-11 0:59 
GeneralImage Pin
alevandro3-Aug-06 4:25
memberalevandro3-Aug-06 4:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 7 Nov 2005


24 bookmarked