Link to home
Start Free TrialLog in
Avatar of Robb Hill
Robb HillFlag for United States of America

asked on

Configuring the App Config to work with smtp

I have the following code snippet that is working to send an email via smtp.  I would like to use an appconfig file to store the host,and to and from email addresses.....I cant seem to figure out how to setup the app config file so that it will work...here is what I ha ve so f ar.

here is my snippet from my config file...
<system.net>
   <mailSettings>
              <smtp from="server@default.net">
                    <network host="127.0.0.1"/></smtp>
</mailSettings>
</system.net>

and here is the code without referencing the appconfig

 Dim mMailMessage As New MailMessage()

            'sender e-mail address.
            mMailMessage.From = New MailAddress("server@blah.net")
            'recipient e-mail address.
            mMailMessage.To.Add(New MailAddress("blah@blah.com"))
            ' Set the subject of the mail message
            mMailMessage.Subject = "ALERT"
            ' Set the body of the mail message
            mMailMessage.Body = "<HTML><BODY><B>ALERT! The system did not process the ADS_Blend Job</B></BODY></HTML>"
            ' Set the format of the mail message body as HTML
            mMailMessage.IsBodyHtml = True
            ' Set the priority of the mail message to normal
            mMailMessage.Priority = MailPriority.Normal

            ' Instantiate a new instance of SmtpClient
            Dim mSmtpClient As New SmtpClient()
            mSmtpClient.Host = "127.0.0.1"
            ' Send the mail message
            mSmtpClient.Send(mMailMessage)

ASKER CERTIFIED SOLUTION
Avatar of igor_alpha
igor_alpha

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Robb Hill

ASKER

i have never seen this syntax.....what would the app config look like if I wanted to add a recipient email address
I am trying to get this piece from the app config file:

 mMailMessage.To.Add(New MailAddress("blah@blah.com"))

actually I was looking to use the .net 2.0 my.settings feature.  I figured it out....its all auto generated....by right clicking on the properties of the project....then chosing settings ..i was able to setup a application level variable.