I tried creating an object m_mailObject.CC.Add(New MailAddress(test1@mailserver.com,test2@mailserver.com)). But the mail just goes to the first recipient. I found out that the MailAddress returns
a count of 1 even if there are two address in it.
In your example above the code will create a new mail adress and set its to and from address. You would have to create a new address for each email. The mail message class to is a collection which can have more than one address in it
First of all sorry my code is to set the mailobject's CC collection i.e m_mailObject.CC.Add(New MailAddress("test1@mailserver.com,test2@mailserver.com")) within quotes (I missed to put the quotes
in the previous sample code). So I am using the MailAddress constructor with one parameter of Address. Why would this create only one count of email address.
I understand, if I have to make it run, I will have to loop and for each item do a CC.Add(...). But isnt the MailAddress supposed to do that?
I think you misread the page. A MailAddress only represents one email address. The MailAddress constructor can accept two parameters, but one is for the email address and the other is for the display name. ie: var ma = new MailAddress("user@site.com", "User's
Display Name").
I may have misunderstood these lines
[A comma is used to separate elements in a list of mail addresses. As a result, a comma should not be used in unquoted display names in a list. The following mail addresses
would be allowed "John, Doe" <user@host>, "Bob, Smith"
user2@host]
But then my question is, which object supports comma seperated elements?
I may have misunderstood these lines
[A comma is used to separate elements in a list of mail addresses. As a result, a comma should not be used in unquoted display names in a list. The following mail addresses
would be allowed "John, Doe" <user@host>, "Bob, Smith"
user2@host]
Ah, yeah, that's a little poorly written. That's just an example showing two different email addresses that are valid.
suvarnav
But then my question is, which object supports comma seperated elements?
Looking around a bit more, I think
this is the method you're looking for. All you need to do is:
suvarnav
Member
7 Points
4 Posts
MailAddress doesnt support multiple comma seperated email address
Feb 23, 2012 04:24 PM|LINK
I tried creating an object m_mailObject.CC.Add(New MailAddress(test1@mailserver.com,test2@mailserver.com)). But the mail just goes to the first recipient. I found out that the MailAddress returns a count of 1 even if there are two address in it.
This http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.aspx link says it supports multiple address.
Any idea why?
Ken Tucker
All-Star
16797 Points
2608 Posts
MVP
Re: MailAddress doesnt support multiple comma seperated email address
Feb 23, 2012 04:35 PM|LINK
In your example above the code will create a new mail adress and set its to and from address. You would have to create a new address for each email. The mail message class to is a collection which can have more than one address in it
Space Coast .Net User Group
suvarnav
Member
7 Points
4 Posts
Re: MailAddress doesnt support multiple comma seperated email address
Feb 23, 2012 05:32 PM|LINK
Thanks for the reply Ken.
First of all sorry my code is to set the mailobject's CC collection i.e m_mailObject.CC.Add(New MailAddress("test1@mailserver.com,test2@mailserver.com")) within quotes (I missed to put the quotes in the previous sample code). So I am using the MailAddress constructor with one parameter of Address. Why would this create only one count of email address.
I understand, if I have to make it run, I will have to loop and for each item do a CC.Add(...). But isnt the MailAddress supposed to do that?
rossisdead2
Participant
1313 Points
300 Posts
Re: MailAddress doesnt support multiple comma seperated email address
Feb 23, 2012 08:51 PM|LINK
I think you misread the page. A MailAddress only represents one email address. The MailAddress constructor can accept two parameters, but one is for the email address and the other is for the display name. ie: var ma = new MailAddress("user@site.com", "User's Display Name").
suvarnav
Member
7 Points
4 Posts
Re: MailAddress doesnt support multiple comma seperated email address
Feb 23, 2012 09:51 PM|LINK
Thanks for the reply,
I may have misunderstood these lines
[A comma is used to separate elements in a list of mail addresses. As a result, a comma should not be used in unquoted display names in a list. The following mail addresses would be allowed "John, Doe" <user@host>, "Bob, Smith" user2@host]
But then my question is, which object supports comma seperated elements?
rossisdead2
Participant
1313 Points
300 Posts
Re: MailAddress doesnt support multiple comma seperated email address
Feb 23, 2012 10:11 PM|LINK
Ah, yeah, that's a little poorly written. That's just an example showing two different email addresses that are valid.
Looking around a bit more, I think this is the method you're looking for. All you need to do is:
m_mailObject.CC.Add("test1@mailserver.com,test2@mailserver.com")which is essentially a shortcut for doing:
Dim emails = "test1@mailserver.com,test2@mailserver.com" For Each e in emails.Split(",") m_mailObject.CC.Add(new MailAddress(e)) Next