将(多封)电子邮件从用户输入的文本中提取为 MailAddress 格式 (.NET)
MailAddress 类不提供解析具有多个电子邮件的字符串的方法。 MailAddressCollection 类 确实,但它只接受 CSV 并且不允许引号内有逗号< /强>。我正在寻找一个文本处理器来根据用户输入创建电子邮件集合,而不受这些限制。
处理器应采用以下任意格式的逗号或分号分隔值:
"First Middle Last" <[email protected]>
First Middle Last <[email protected]>
[email protected]
"Last, First" <[email protected]>
The MailAddress class doesn't provide a way to parse a string with multiple emails. The MailAddressCollection class does, but it only accepts CSV and does not allow commas inside of quotes. I am looking for a text processor to create a collection of emails from user input without these restrictions.
The processor should take comma- or semicolon-separated values in any of these formats:
"First Middle Last" <[email protected]>
First Middle Last <[email protected]>
[email protected]
"Last, First" <[email protected]>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
MailAddressCollection.Add() 例程支持逗号分隔的地址列表。
输出:
The MailAddressCollection.Add() routine supports a comma delimited address list.
Output:
开源库DotNetOpenMail(旧)有一个EmailAddress类,可以解析几乎所有合法形式的电子邮件地址,和 EmailAddressCollection。你可以从那里开始。
The open source library DotNetOpenMail (old) has an EmailAddress class that can parse almost all legal forms of email addresses, and an EmailAddressCollection. You could start there.
在提出相关问题,我意识到一个更好的方法:
该方法通过了以下测试:
After asking a related question, I became aware of a better method:
This method passes the following tests:
实际上,MailAddressCollection 确实支持逗号分隔的地址,即使引号内有逗号也是如此。 我最近发现的真正问题,是 CSV 列表必须已经编码为 ASCII 字符集,即。 Unicode 地址的 Q 编码或 B 编码。
尽管我在 Sasa 中提供了 B 编码,但基类库中没有执行此编码的函数。我还刚刚添加了一个电子邮件解析功能,可以解决该线程中的问题。
Actually, MailAddressCollection DOES support comma-delimited addresses, even with the commas inside the quotes. The real problem I recently discovered, is that the CSV list must already be encoded into the ASCII character set, ie. Q-encoded or B-encoded for Unicode addresses.
There is no function in the base class libraries to perform this encoding, although I provide B-encoding in Sasa. I also just added an e-mail parsing function which addresses the question in this thread.