Solved

ASP.NET/VB - Email multiple addresses

Posted on 2013-11-12
4
368 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
4 Comments
 
LVL 33

Accepted Solution

by:
paulmacd 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now