4

I've just switched from the deprecated System.Web.Mail.MailAddress to System.Net.Mail.MailAddress, but it doesn't seem to be particularly flexible when passing in a parameter holding multiple addresses when using the new System.Net.Mail.MailAddress.To.Add.

string emailAdd= "email1@emailus.com; email2@emailus.com";

System.Net.Mail.MailAddress.To.Add(emailAdd);

In the above example, email2@emailus.com is emailed successfully, but email1@emailus.com is not. I really need a way to do this since my addresses are defined in another class and passed to an email() method via a parameter. I'm simply not passing five parameters for 5 separate emails. Or indeed one and splicing on my end, .Web version is proving to be way more versatile.

This question is not a duplicate of the suggested one. The answer to the "duplicate" is add them individually, I want to add multiple addresses simultaneously. Since there is a way to do this, this question is more relevant than the one I'm accused of duplicating.

notAChance
  • 1,360
  • 4
  • 15
  • 47
  • Possible duplicate of [How to send email to multiple address using System.Net.Mail](https://stackoverflow.com/questions/7498968/how-to-send-email-to-multiple-address-using-system-net-mail) – Ashiqur Rahman Emran Nov 14 '17 at 16:34
  • It isn't. He asks how to send to multiple emails, I'm asking how to send to multiple emails with one parameter. – notAChance Nov 14 '17 at 16:35
  • System.Net.Mail.MailAddress To is not a member of mail address. Downvote – pianocomposer Oct 06 '21 at 17:33
  • @pianocomposer, good spot and good downvote. I'm not sure where I got that from... has the API changed? Maybe this is outdated. – notAChance Oct 07 '21 at 22:44

2 Answers2

6

According to MSDN, the .Add() method accepts a string of comma-delimited addresses, rather than semicolon-delimited.

Therefore either changing the parameter that you are passing in to a comma-delimited string, if possible, or adding functionality to your email method to replace the semicolons with commas should resolve the issue.

Diado
  • 2,229
  • 3
  • 18
  • 21
2

In this purpose you can follow the function Parameter that it denotes actually which is show that you can use comma delimiter and function parameter is denoted as addresses which identify that you can send multiple email together using it

mail.To.Add("to1mailaddress@domain,to2mailaddress@domain");