473,789 Members | 2,441 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.GetUs erName(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(To Address,
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}Mes sage: {1}{0}{0} Stack Trace:{0}{2}",
System.Environm ent.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 2399
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_C lick(object sender, EventArgs e)
{
string queryString = "Select Email From tblMailer";
string constring = "Data Source=GLSDBS03 ;Initial
Catalog=CCTS;Pe rsist Security Info=True;User
ID=UserID;Passw ord=Password";
using (SqlConnection connection = new
SqlConnection(c onstring))
{
connection.Open ();

SqlCommand command = new SqlCommand(quer yString,
connection);
SqlDataReader reader = command.Execute Reader();
while (reader.Read())
{
string captured = Convert.ToStrin g(reader["EMail"]);
try
{
SmtpClient mailSvr = new SmtpClientYour SMTP
CLient);
MailAddress from = new MailAddress(You r From
Address);
MailAddress to = new MailAddress(cap tured);
MailMessage msg = new MailMessage(fro m, to);
msg.Subject = "JACOBS CCTS Labor Upload";
msg.Body = "The attached text file contains Labor
Hours. " + Environment.New Line + Environment.New Line;
Attachment attach = new Attachment("\\\ \glsdbs03\\d
$\\File\\LaborF ile.txt");
msg.Attachments .Add(attach);
mailSvr.Send(ms g);
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...@lifeti meinc.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.GetUs erName(strUser)

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

'(1) Create the MailMessage instance
Dim mm As New System.Net.Mail .MailMessage(To Address,
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}Mes sage: {1}{0}{0} Stack Trace:{0}{2}",
System.Environm ent.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(toA ddress1,fromAdd ress);
mm.To.Add(new MailAddress(toA ddress2));

-- 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.GetUs erName(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(To Address,
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}Mes sage: {1}{0}{0} Stack Trace:{0}{2}",
System.Environm ent.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*****@lifeti meinc.comwrote in message
news:uC******** ********@TK2MSF TNGP03.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**@markNOSPA Mrae.netwrote in message
news:eH******** ******@TK2MSFTN GP03.phx.gbl...
"David C" <dl*****@lifeti meinc.comwrote in message
news:uC******** ********@TK2MSF TNGP03.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
1715
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 there have recommendations for an alternate method of locking our MDE files to allow only licensed access? We simply want to allow the user to install the program and get a
5
2237
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 this class that will send email, however my class will not seem to recognise the system.web.mail.mailmessage. my first impression on this is that I may have to use some sort of third
0
1456
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 = "to@address.com mail.From = "from@address.com" mail.Subject = "this is a test email." mail.Body = "Some text goes here"
8
5474
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 IIS. The reading I have done(alot) has been pretty useless in helping me understand the various bits required. The error I get is: On a pc running win2k with IIS and Lotus Notes System.Runtime.InteropServices.SEHException: External component has...
1
8186
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 the members of my organization. I think my problem is incorrectly setting the settings on my server or an authentication problem. Here is the code I have written to send a test message: -----Code Begins: Sensitive Information Replaced by -----...
2
3501
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 application, and also succeeds from the asp.net page with BodyFormat=MailFormat.Text. I've recently upgraded from W2K SP4 to WinXP SP2 and am using .Net Framework v1.1 SP1. The code worked fine under W2K SP4.
1
5909
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 using For XML explicit, and it returns an xml reader. Then the following: xmlRdr.MoveToContent(); string myTemp = xmlRdr.ReadOuterXml();
0
1553
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. However, I want a summarized e-mail (with slightly different content) to get sent to the sender, and this fails unless the “sender”has their domain name on the same server. Essentially, it has the following problem:
3
2867
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 message "The specified string is not in the form required for an e-mail address". I have conducted further testing and evidently the SmtpClient class Send method does not like the period "." between the "john" and "doe". If I conduct a test with an...
5
8339
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 by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. Exception Details: for the permission of type
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9979
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6765
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4090
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.