Solved

ASP.NET/VB - Email multiple addresses

Posted on 2013-11-12
4
383 Views
Last Modified: 2013-11-12
This code sends a single email to "email1@example.com".  How can I send an email to three addresses:
email1@example.com
email2@example.com
email3@example.com


Imports System.Net.Mail
Imports System.IO
Imports System.Threading
Imports System.Text.RegularExpressions

Partial Class contact_submit
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim EmailBody As StringBuilder = New StringBuilder

        Dim message As MailMessage = New MailMessage(ConfigurationManager.AppSettings("ContactEmailFrom").ToString(), "email1@example.com")

            EmailBody.Append("Name: " + Request.Params("Full_Name") + Environment.NewLine + Environment.NewLine)
            message.IsBodyHtml = False
            message.Body = EmailBody.ToString()
            message.From = New System.Net.Mail.MailAddress(ConfigurationManager.AppSettings("ContactEmailFrom").ToString())
            message.Subject = "Sales Inquiry"
            message.ReplyTo = New MailAddress(Request.Params("Email_Address"))

            Dim SmtpMail As New SmtpClient
            Dim basicAuthenticationInfo As New System.Net.NetworkCredential(ConfigurationManager.AppSettings("SMTPUser").ToString(), ConfigurationManager.AppSettings("SMTPPassword").ToString())

            SmtpMail.Host = ConfigurationManager.AppSettings("SMTPServer").ToString()
            SmtpMail.UseDefaultCredentials = False
            SmtpMail.Credentials = basicAuthenticationInfo
            SmtpMail.Send(message)
      
    End Sub
End Class

Open in new window

0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 34

Accepted Solution

by:
Paul MacDonald earned 300 total points
ID: 39641637
       Dim message As MailMessage = New MailMessage(ConfigurationManager.AppSettings("ContactEmailFrom").ToString(), "email1@example.com;email2@example.com;email3@example.com")
0
 
LVL 15

Assisted Solution

by:pateljitu
pateljitu earned 200 total points
ID: 39641644
Please try code as provided, added multiple TO recipients:
Imports System.Net.Mail
Imports System.IO
Imports System.Threading
Imports System.Text.RegularExpressions

Partial Class contact_submit
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim EmailBody As StringBuilder = New StringBuilder

        Dim message As MailMessage = New MailMessage()

            EmailBody.Append("Name: " + Request.Params("Full_Name") + Environment.NewLine + Environment.NewLine)
            message.IsBodyHtml = False
            message.Body = EmailBody.ToString()
            message.From = New System.Net.Mail.MailAddress(ConfigurationManager.AppSettings("ContactEmailFrom").ToString())
            message.To.Add(new MailAddress("email1@example.com"));
            message.To.Add(new MailAddress("email2@example.com"));
            message.To.Add(new MailAddress("email3@example.com"));
            message.Subject = "Sales Inquiry"
            message.ReplyTo = New MailAddress(Request.Params("Email_Address"))

            Dim SmtpMail As New SmtpClient
            Dim basicAuthenticationInfo As New System.Net.NetworkCredential(ConfigurationManager.AppSettings("SMTPUser").ToString(), ConfigurationManager.AppSettings("SMTPPassword").ToString())

            SmtpMail.Host = ConfigurationManager.AppSettings("SMTPServer").ToString()
            SmtpMail.UseDefaultCredentials = False
            SmtpMail.Credentials = basicAuthenticationInfo
            SmtpMail.Send(message)
      
    End Sub
End Class
                                  

Open in new window

0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 39641667
Give the To email address as comma seperated.

Dim message As MailMessage = New MailMessage(ConfigurationManager.AppSettings("ContactEmailFrom").ToString(), "email1@example.com,email2@example.com,email3@example.com") 

Open in new window

0
 
LVL 16

Author Comment

by:hankknight
ID: 39641977
The commas do not work but the other ideas do.  Thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question