?
Solved

ASP.NET/VB - Email multiple addresses

Posted on 2013-11-12
4
Medium Priority
?
386 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 1200 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 800 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

777 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