473,657 Members | 3,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MailAddress string format

Hello,
I am putting email function into a web app I am making using C#. I am
struggling to find out the proper format for the string of To email
addresses. I want to put multiple addresses in the string, but
everything I try does not work.
Here is my code:
protected void SendEmail_Click (object sender, EventArgs e)
{
string emailSubject = "Test Subject";
string emailTo = "emailaddress1; emailaddress2";
string emailFrom = "emailaddre ss";
string emailBody = "Test Email";
string SMTPServer = "localhost" ;

this.SendRemind erEmail(this.Co ntext, emailSubject, emailTo,
emailFrom, emailBody, SMTPServer);
}

Obviously I will replace "emailaddre ss1" with a real email address, I
just left out the email addresses for security reasons. I have tried
putting semicolon with no space, semicolon with a space, comma with no
space, and comma with a space, to divide the email addresses. Nothing
works.
Thanks.
Greg

Feb 16 '06 #1
16 14869
What is it that isn't working? Do you get an error, does it only send
to one or the other, or does it not send at all?

Feb 16 '06 #2
This is the error I get:

The specified string is not in the form required for an e-mail address.

I just am trying to find the proper format for inserting multiple email
addresses in the code. When the administrator clicks a button, it is
supposed to send out an email. It works just fine when I have one
email address in there, but when I try to put more than one, it does
not work. I figure there has to be a way to do more than one email
address, I just can't get the format right.
Thanks

Feb 16 '06 #3
The System.Net.Mail Message class has a To property which is a
collection of MailAddresses ( MailAddressColl ection). To send an email
to multiple recipients you have to add a MailAddress to that
collection. Here is some sample code:

MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress("em ****@test.com") );
msg.To.Add(new MailAddress("em ****@test.com") );
.....
.....

Obviously this would have to be programed in your SendReminderEma il
method. What you can do is have the emailTo parameter to be an array
of stings and then inside your method do a foreach on this string array
and then add the address to the collection like I shown above.

I hope this helps

Feb 16 '06 #4
Thanks for the help. I will look into doing it this way.

Feb 16 '06 #5
It looks like foreach loops can not work with objects of type
MailMessage. Do you have another route you might suggest going?

Feb 16 '06 #6


"gd*****@yahoo. com" wrote:
string emailTo = "emailaddress1; emailaddress2";

Obviously I will replace "emailaddre ss1" with a real email address, I
just left out the email addresses for security reasons. I have tried
putting semicolon with no space, semicolon with a space, comma with no
space, and comma with a space, to divide the email addresses. Nothing
works.


For me with SmtpClient semi-colons worked for me in 1.1 and commas worked in
2.0.
Feb 16 '06 #7
Hi,


Obviously I will replace "emailaddre ss1" with a real email address, I
just left out the email addresses for security reasons. I have tried
putting semicolon with no space, semicolon with a space, comma with no
space, and comma with a space, to divide the email addresses. Nothing
works.


semicolon with no space works fine, I just wrote such a piece of code 30 min
ago, what error you get?
wrap everything in a try/catch and drill down the Exception, IIRC the
second InnerException will have the more detailed explanation of the error.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Feb 16 '06 #8
Hi,

<gd*****@yahoo. com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
It looks like foreach loops can not work with objects of type
MailMessage. Do you have another route you might suggest going?


What you mean with that?

Here is the code I used, it's in VB.net but it is simple enough to
understand it

Dim rcpt As System.Text.Str ingBuilder = New
System.Text.Str ingBuilder
Dim mail As System.Web.Mail .MailMessage = New
System.Web.Mail .MailMessage

For Each dr As System.Data.Dat aRow In
dm.GetUsersRequ iredEmails().Ta bles(0).Rows
If rcpt.Length > 0 Then
rcpt.Append(";" )
End If
rcpt.Append(dr( "email"))
Next
mail.To = rcpt.ToString()
mail.From = "si**@ffdot.sta te.ffl.us"
mail.Subject = "Level 3 incident"

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Feb 16 '06 #9
Hi Ignacio.
Maybe that is a difference with C# and VB, because it says that foreach
loops don't work with anything of Type MailMessage.
Also, I don't know VB, I started learning programming using C#. I am
fairly new to it, so I can't really translate from VB to C# yet. I
think I might just use a Stored Proc because I only need to grab
certain addresses.

Feb 16 '06 #10

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

Similar topics

2
36836
by: Bob | last post by:
I'm having trouble the string.Format() throwing exceptions and I can't figure out what I am doing wrong. Given the following setup code: string str = { "one", "two", "three", "four" }; double val = { 1.0, 2.0, 3.0, 4.0 }; string fmt = "{0} {1} {2} {3}"; The following variations of string.Format() will work just fine with strings: string s1 = String.Format(fmt, str, str, str, str); // works
7
6490
by: Alpha | last post by:
Hi, I'm maintaining C# code and am fairly new with C# programming. I'm looking for codes that's droping the 2nd digit of a nuber printed out and I suspect it's the code below. Can someone tell me where I can look up explaination on the String.Format, the format string part like "("{0:.#0}". What's the trailing 0 and what is that "0:" means? I assume the "#" is the place holder character for th value obtain after the comma in the code. ...
3
485
by: Dominique Vandensteen | last post by:
after the very small & vs string.format discussion I did some speed tests... loop of 1.000.000 concatenations of 5 public string variables in a class gave following results: result = a & b & c & d & e +/- 420ms
4
1630
by: David Morris | last post by:
Hi Could somebody please explain what the following line of code means String.Format("{0}\{1}.{2:00}", C:\, myfile.txt, 1 It's actually the first argument that I don't understand. What is the purpose of "{0}\{1}.{2:00}"? I've been using VB .NET for a year now, and have never come across anything like this Best Regards David Morris
38
807
by: nobody | last post by:
I know that given a FormatString and a DateTime you can use DateTime.ToString(...) to convert the DateTime to a String. My question is how can you turn that around? Given a String and a FormatString, how can you convert the String back to a DateTime? DateTime.Parse(...) doesn't use the FormatString. Now admitedly, if the format string is just "MM", it can't be done. But if the format string is "yyyyMMdd", or "ddMMMyyyy hhmmsst", it...
7
3106
by: L. Scott M. | last post by:
Have a quick simple question: dim x as string x = "1234567890" ------------------------------------------------------- VB 6 dim y as string
8
4989
by: Lucky | last post by:
hi guys! back again with another query. the problem is like this. i want to print a line like this: "---------------------------------------------" the easiest way is to simply assign it to string and print it. but i want to use the String.Format() method if possible to do it.
1
1377
by: pennyfx | last post by:
I ran into a strange problem today. I tried to send mail to a strange but valid email address, but the MailAddress("") object choked on me. It threw a formating exception saying it was not a valid email address. homer-..-sim-..-pson@sympatico.ca This is not the a real account, but is a valid email address according to RFC2822 http://www.ietf.org/rfc/rfc2822.txt I think that the two dots together are what is messing it up. Has anyone...
5
9017
by: jpenguin | last post by:
I'm doing a simple program to learn java. I have the input and math parts right. It just isn't displaying right. It outputs a list of about 11 things-- with the format "string $ xx.xx" In each line the '$'s should be aligned and the decimal point should be aligned. This is what it currently shows-http://img140.imageshack.us/img140/2684/screenshot20090910at357.jpg package excercise6; import java.swing.*; /** * * @author dye1107...
0
8820
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
8718
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...
1
8499
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7314
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
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
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
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
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
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.