[英]System.Net.Mail.MailAddress send to multiple emails with one parameter
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
. 我刚刚从不推荐使用的System.Web.Mail.MailAddress
切换到System.Net.Mail.MailAddress
,但是在使用新的System.Net.Mail.MailAddress.To.Add
传递包含多个地址的参数时,它似乎不是特别灵活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. 在上面的示例中, email2@emailus.com
已成功通过电子邮件发送,而email1@emailus.com
未成功通过电子邮件发送。 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. 我确实需要一种方法,因为我的地址是在另一个类中定义的,并通过参数传递给email()
方法。 I'm simply not passing five parameters for 5 separate emails. 我只是没有为5个单独的电子邮件传递五个参数。 Or indeed one and splicing on my end, .Web
version is proving to be way more versatile. 甚至可以说是我的最终选择, .Web
版本被证明更加通用。
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. 由于有一种方法可以解决此问题,因此这个问题比我被指控重复的问题更为重要。
According to MSDN , the .Add()
method accepts a string of comma-delimited addresses, rather than colon-delimited. 根据MSDN , .Add()
方法接受一串用逗号分隔的地址,而不是冒号分隔的地址。
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 colons with commas should resolve the issue. 因此,如果可能的话,将您要传入的参数更改为逗号分隔的字符串,或者在电子邮件方法中添加功能以用逗号替换冒号都可以解决此问题。
为此,您可以遵循实际上表示的功能参数,这表明您可以使用逗号定界符,而功能参数则表示为地址,该地址标识您可以使用该地址一起发送多封电子邮件
mail.To.Add("to1mailaddress@domain,to2mailaddress@domain");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.