简体   繁体   English

System.Net.Mail.MailAddress使用一个参数发送到多封电子邮件

[英]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.

相关问题 RegEx由System.Net.Mail.MailAddress使用 - Is RegEx used by System.Net.Mail.MailAddress System.Net.Mail.MailAddress不允许Gmail GROUP联系人 - System.Net.Mail.MailAddress does not allow Gmail GROUP contact 无法将System.Net.Mail.MailAddress序列化为Json - Unable to serialize System.Net.Mail.MailAddress to Json 无法将类型“System.Net.Mail.MailAddress”隐式转换为“SendGrid.Helpers.Mail.EmailAddress” - Cannot implicitly convert type 'System.Net.Mail.MailAddress' to 'SendGrid.Helpers.Mail.EmailAddress' 使用System.Net.Mail.MailAddress或其他库指定.eml文件名 - Specify .eml file name using System.Net.Mail.MailAddress or other library 为什么 System.Net.Mail.MailAddress 构造函数在域部分解析带有斜杠“/”的电子邮件? - Why System.Net.Mail.MailAddress constructor parses email with slash "/" in domain part? System.Net.Mail.MailAddress验证电子邮件缺少TLD,认为我@有效 - System.Net.Mail.MailAddress validates email missing TLD, considers me@there valid 如何使用 System.Net.Mail 向多个地址发送电子邮件 - How to send email to multiple address using System.Net.Mail 使用 System.Net.Mail 通过 smtp 服务器加速发送多封电子邮件 - Speed up sending multiple emails through smtp server using System.Net.Mail 使用System.Net.Mail在公​​司外部未收到发送电子邮件 - Sending emails are not received outside the company using System.Net.Mail
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM