Sending E-mails From ASP.Net


Step 1: Place the following in your web.config file, making sure to replace the username and password fields with a valid inbox created from within the control panel:
 
<configuration>

  <appSettings/>

    <system.net>

      <mailSettings>

        <smtp from="validaddress@yourdomain.com">

          <network host="mail.reliablesite.net" port="25" password="password" userName="validaddress@yourdomain.com" defaultCredentials="false" />

        </smtp>

      </mailSettings>

    </system.net>

  </appSettings>

</configuration>


Step 2: From within the page, use the code below replacing the from, to, subject, and body fields:
 
Dim mm As New MailMessage()

mm.From = New MailAddress("Fromanyone@somedomain.com", "John Doe")

mm.To.Add(New MailAddress("FirstRecipient@recipientdomain.com"))

mm.To.Add(New MailAddress("SecondRecipient@seconddomain.com"))

mm.Subject = "Subject line"

mm.Body = "This is the message...it can include html tags for formatting"

mm.IsBodyHtml = True

Dim smtp As New SmtpClient

smtp.Send(mm)

Add Feedback