473,396 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

System.Net.Mail to address

I would like to have an email go to 2 email addresses but when I try it by
separating with semicolon or comma it fails. Can anyone help? below is my
code (see ToAddress string). Thanks.

David
strUser = UtilClass.GetUserName(strUser)

'!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
Const ToAddress As String = "me@myemail.com"
Const FromAddress As String = "me@myemail.com"

'(1) Create the MailMessage instance
Dim mm As New System.Net.Mail.MailMessage(ToAddress,
FromAddress)

'(2) Assign the MailMessage's properties
mm.Subject = "Fileroom unhandled exception occurred!"
mm.Body = "User getting error is " & strUser & vbCrLf & _
String.Format("An unhandled exception
occurred:{0}Message: {1}{0}{0} Stack Trace:{0}{2}",
System.Environment.NewLine, ex.Message, ex.StackTrace)
mm.IsBodyHtml = False

'(3) Create the SmtpClient object
Dim smtp As New System.Net.Mail.SmtpClient

'(4) Send the MailMessage (will use the Web.config settings)
smtp.Send(mm)
Nov 21 '07 #1
4 2377
Great Minds must think alike. I just finished this not more than 15
minutes ago. There may be a better way to do it, but I know that this
works.

protected void btnSendUpload_Click(object sender, EventArgs e)
{
string queryString = "Select Email From tblMailer";
string constring = "Data Source=GLSDBS03;Initial
Catalog=CCTS;Persist Security Info=True;User
ID=UserID;Password=Password";
using (SqlConnection connection = new
SqlConnection(constring))
{
connection.Open();

SqlCommand command = new SqlCommand(queryString,
connection);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
string captured = Convert.ToString(reader["EMail"]);
try
{
SmtpClient mailSvr = new SmtpClientYour SMTP
CLient);
MailAddress from = new MailAddress(Your From
Address);
MailAddress to = new MailAddress(captured);
MailMessage msg = new MailMessage(from, to);
msg.Subject = "JACOBS CCTS Labor Upload";
msg.Body = "The attached text file contains Labor
Hours. " + Environment.NewLine + Environment.NewLine;
Attachment attach = new Attachment("\\\\glsdbs03\\d
$\\File\\LaborFile.txt");
msg.Attachments.Add(attach);
mailSvr.Send(msg);
lbStatus.Text = "Labor has been Sent.";
}
catch (Exception ex)
{
lbStatus.Text = ex.Message;
}
}
}
}


I hope this helps

On Nov 21, 4:00 pm, "David C" <dlch...@lifetimeinc.comwrote:
I would like to have an email go to 2 email addresses but when I try it by
separating with semicolon or comma it fails. Can anyone help? below is my
code (see ToAddress string). Thanks.

David
strUser = UtilClass.GetUserName(strUser)

'!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
Const ToAddress As String = "m...@myemail.com"
Const FromAddress As String = "m...@myemail.com"

'(1) Create the MailMessage instance
Dim mm As New System.Net.Mail.MailMessage(ToAddress,
FromAddress)

'(2) Assign the MailMessage's properties
mm.Subject = "Fileroom unhandled exception occurred!"
mm.Body = "User getting error is " & strUser & vbCrLf & _
String.Format("An unhandled exception
occurred:{0}Message: {1}{0}{0} Stack Trace:{0}{2}",
System.Environment.NewLine, ex.Message, ex.StackTrace)
mm.IsBodyHtml = False

'(3) Create the SmtpClient object
Dim smtp As New System.Net.Mail.SmtpClient

'(4) Send the MailMessage (will use the Web.config settings)
smtp.Send(mm)
Nov 21 '07 #2
in smtp, you write out a header per address, not a comma seperated list. to
support this mailmessage has a To collection, which you add as many addresses
as you want:

var mm = new MailMessage(toAddress1,fromAddress);
mm.To.Add(new MailAddress(toAddress2));

-- bruce (sqlwork.com)
"David C" wrote:
I would like to have an email go to 2 email addresses but when I try it by
separating with semicolon or comma it fails. Can anyone help? below is my
code (see ToAddress string). Thanks.

David
strUser = UtilClass.GetUserName(strUser)

'!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
Const ToAddress As String = "me@myemail.com"
Const FromAddress As String = "me@myemail.com"

'(1) Create the MailMessage instance
Dim mm As New System.Net.Mail.MailMessage(ToAddress,
FromAddress)

'(2) Assign the MailMessage's properties
mm.Subject = "Fileroom unhandled exception occurred!"
mm.Body = "User getting error is " & strUser & vbCrLf & _
String.Format("An unhandled exception
occurred:{0}Message: {1}{0}{0} Stack Trace:{0}{2}",
System.Environment.NewLine, ex.Message, ex.StackTrace)
mm.IsBodyHtml = False

'(3) Create the SmtpClient object
Dim smtp As New System.Net.Mail.SmtpClient

'(4) Send the MailMessage (will use the Web.config settings)
smtp.Send(mm)
Nov 21 '07 #3
"David C" <dl*****@lifetimeinc.comwrote in message
news:uC****************@TK2MSFTNGP03.phx.gbl...
>I would like to have an email go to 2 email addresses but when I try it by
separating with semicolon or comma it fails.
Well it would do - it's a collection...
http://www.systemnetmail.com/faq/3.2.3.aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 21 '07 #4
Perfect. Thanks everyone.

David
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:eH**************@TK2MSFTNGP03.phx.gbl...
"David C" <dl*****@lifetimeinc.comwrote in message
news:uC****************@TK2MSFTNGP03.phx.gbl...
>>I would like to have an email go to 2 email addresses but when I try it by
separating with semicolon or comma it fails.

Well it would do - it's a collection...
http://www.systemnetmail.com/faq/3.2.3.aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 21 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Lauren Wilson | last post by:
Hi Folks, We've been using Crypto ++32 to control licensed access to our widely distributed Access 2K app. Unfortunately, Sampson Multimedia appears to be out of business. Does anyone out...
5
by: martin | last post by:
Hi, I have created a class that is totally seperate from my web application. However this class is used extensivly by the web application for stuff like data access. I wish to add a function to...
0
by: techie | last post by:
I'm trying to use system.web.mail to send an email, but the smtp server requires authentication. I came across some info about fields property Dim mail As New MailMessage() mail.To =...
8
by: marcmc | last post by:
Trying to send an eMail frommy vb.net App. Is there anybody out there that has successfully done this? I am having major problems and need a step by step guide into the world of system.web and...
1
by: Eric Sheu | last post by:
Greetings, I have been searching the web like mad for a solution to my SMTP problem. I am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a web site I have created to...
2
by: Ryan | last post by:
Hi, I receive an access denied error (see below) when attempting to send an email with BodyFormat=MailFormat.Html from an asp.net page. Exactly the same code works fine in a console...
1
by: theWizard1 | last post by:
The following sends my email, but the attachment is empty. The attachment should contain the data that is in the string that was created from the xmlReader. I have a stored procedure written...
0
by: Neo Geshel | last post by:
I am experiencing an inconsistency with System.Net.Mail. I have a web form on a site. The form gets filled, and one copy gets sent to the recipient (info@domain.com). This works just fine. ...
3
by: =?Utf-8?B?UGhpbGlw?= | last post by:
I switched from System.Web.Mail to System.Net.Mail, however I am now reconsidering that move because if I send an email to an email address in the form john.doe@yahoo.com, I receive an error...
5
by: Henry Stock | last post by:
I am trying to understand the following error: Any thing you can tell me about this is appreciated. Security Exception Description: The application attempted to perform an operation not allowed...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.