Click here to Skip to main content
12,885,784 members (44,335 online)
Click here to Skip to main content
Add your own
alternative version


24 bookmarked
Posted 7 Nov 2005

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

, 20 Feb 2006
Rate this:
Please Sign up or sign in to vote.
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

You may also be interested in...


Comments and Discussions

Questionhow to create mail address box? Pin
duraie19-Mar-08 23:33
memberduraie19-Mar-08 23:33 
AnswerRe: how to create mail address box? Pin
Member 45300646-May-11 23:59
memberMember 45300646-May-11 23:59 
GeneralImage Pin
alevandro3-Aug-06 3:25
memberalevandro3-Aug-06 3: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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 21 Feb 2006
Article Copyright 2005 by creativesri
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid