System.Net.Mail 替代方案

发布于 2024-08-09 06:52:44 字数 408 浏览 2 评论 0原文

我正在开发一个用 C# 编写的邮件服务器安排电子邮件的工具。我一直在使用 System.Net.Mail 类来发送邮件。

最近,我遇到了有关 RFC 违规和其他问题的各种问题,例如 SmtpClient 未根据协议结束 SMTP 会话。这些问题中的每一个都会导致较高的垃圾邮件分数并影响电子邮件传送,因此我需要解决这些问题。

我想知道其他人为了解决这些问题采取了什么措施。人们是否开始使用第三方组件,如果是的话,是哪一个?

编辑:作为支持证据,请参阅:http://www .codeproject.com/KB/IP/MailMergeLib.aspx

I'm working on a tool that schedules emails with our mail server in C#. I had been using the System.Net.Mail classes to send the mail.

Recently I've come across various issues with regards to RFC violations and other issues, such as SmtpClient not ending the SMTP session according to protocol. Each of these problems is counting toward a high spam score and affecting email delivery, so I need a solution to these problems.

I'm wondering what other people have resorted to in order to resolve these issues. Have people started using a third part component, if so which one?

EDIT: As supporting evidence, please see: http://www.codeproject.com/KB/IP/MailMergeLib.aspx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

岁吢 2024-08-16 06:52:44

一种替代方案是 MailKit。具有大量功能,可以通过 CancellationToken 可靠地取消发送,因此不存在问题SmtpClient表示它不遵守指定的超时。
NuGet 上也有大量下载。

甚至最近的文档 推荐它:

[System.Obsolete("SmtpClient 及其网络类型设计不佳,我们强烈建议您使用 https: //github.com/jstedfast/MailKithttps://github.com/jstedfast/MimeKit< /a> 相反")]
公共类SmtpClient:IDisposable


One alternative is MailKit. Has a ton of features, sending can be reliably cancelled via a CancellationToken, so it doesn't have the problem of SmtpClient that it doesn't respect the specified timeout.
Has a lot of downloads on NuGet, too.

Even the recent documentation recommends it:

[System.Obsolete("SmtpClient and its network of types are poorly designed, we strongly recommend you use https://github.com/jstedfast/MailKit and https://github.com/jstedfast/MimeKit instead")]
public class SmtpClient : IDisposable

不乱于心 2024-08-16 06:52:44

如果您有 Microsoft Exchange 2007 电子邮件服务器,那么您可以选择使用它的 网络发送电子邮件的服务方向。 Web 服务本身有点奇怪,但我们能够封装这种奇怪之处并使其像我们的 SMTP 类一样工作。

首先,您需要像这样引用 Exchange Web 服务:https://mail.yourwebserver.com/EWS/Services.wsdl" rel="nofollow noreferrer">https:// /mail.yourwebserver.com/EWS/Services.wsdl

这是一个示例:

public bool Send(string From, MailAddress[] To, string Subject, string Body, MailPriority Priority, bool IsBodyHTML, NameValueCollection Headers)
{
    // Create a new message.
    var message = new MessageType { ToRecipients = new EmailAddressType[To.Length] };

    for (int i = 0; i < To.Length; i++)
    {
        message.ToRecipients[i] = new EmailAddressType { EmailAddress = To[i].Address };
    }

    // Set the subject and sensitivity properties.
    message.Subject = Subject;
    message.Sensitivity = SensitivityChoicesType.Normal;
    switch (Priority)
    {
        case MailPriority.High:
            message.Importance = ImportanceChoicesType.High;
            break;

        case MailPriority.Normal:
            message.Importance = ImportanceChoicesType.Normal;
            break;

        case MailPriority.Low:
            message.Importance = ImportanceChoicesType.Low;
            break;
    }

    // Set the body property.
    message.Body = new BodyType
                   {
                       BodyType1 = (IsBodyHTML ? BodyTypeType.HTML : BodyTypeType.Text),
                       Value = Body
                   };

    var items = new List<ItemType>();
    items.Add(message);

    // Create a CreateItem request.
    var createItem = new CreateItemType()
                     {
                         MessageDisposition = MessageDispositionType.SendOnly,
                         MessageDispositionSpecified = true,
                         Items = new NonEmptyArrayOfAllItemsType
                                 {
                                     Items = items.ToArray()
                                 }
                     };


    var imp = new ExchangeImpersonationType
              {
                  ConnectingSID = new ConnectingSIDType { PrimarySmtpAddress = From }
              };
    esb.ExchangeImpersonation = imp;

    // Call the CreateItem method and get its response. 
    CreateItemResponseType response = esb.CreateItem(createItem);

    // Get the items returned by CreateItem.
    ResponseMessageType[] itemsResp = response.ResponseMessages.Items;
    foreach (ResponseMessageType type in itemsResp)
    {
        if (type.ResponseClass != ResponseClassType.Success)
            return false;
    }

    return true;
}

If you have a Microsoft Exchange 2007 email server then you have an option to use it's web service direction to send email. The web service itself is a bit strange but we were able to encapsulate the weirdness and make it work just like our SMTP class.

First you would need to make a reference to the exchange web service like this: https://mail.yourwebserver.com/EWS/Services.wsdl

Here is an example:

public bool Send(string From, MailAddress[] To, string Subject, string Body, MailPriority Priority, bool IsBodyHTML, NameValueCollection Headers)
{
    // Create a new message.
    var message = new MessageType { ToRecipients = new EmailAddressType[To.Length] };

    for (int i = 0; i < To.Length; i++)
    {
        message.ToRecipients[i] = new EmailAddressType { EmailAddress = To[i].Address };
    }

    // Set the subject and sensitivity properties.
    message.Subject = Subject;
    message.Sensitivity = SensitivityChoicesType.Normal;
    switch (Priority)
    {
        case MailPriority.High:
            message.Importance = ImportanceChoicesType.High;
            break;

        case MailPriority.Normal:
            message.Importance = ImportanceChoicesType.Normal;
            break;

        case MailPriority.Low:
            message.Importance = ImportanceChoicesType.Low;
            break;
    }

    // Set the body property.
    message.Body = new BodyType
                   {
                       BodyType1 = (IsBodyHTML ? BodyTypeType.HTML : BodyTypeType.Text),
                       Value = Body
                   };

    var items = new List<ItemType>();
    items.Add(message);

    // Create a CreateItem request.
    var createItem = new CreateItemType()
                     {
                         MessageDisposition = MessageDispositionType.SendOnly,
                         MessageDispositionSpecified = true,
                         Items = new NonEmptyArrayOfAllItemsType
                                 {
                                     Items = items.ToArray()
                                 }
                     };


    var imp = new ExchangeImpersonationType
              {
                  ConnectingSID = new ConnectingSIDType { PrimarySmtpAddress = From }
              };
    esb.ExchangeImpersonation = imp;

    // Call the CreateItem method and get its response. 
    CreateItemResponseType response = esb.CreateItem(createItem);

    // Get the items returned by CreateItem.
    ResponseMessageType[] itemsResp = response.ResponseMessages.Items;
    foreach (ResponseMessageType type in itemsResp)
    {
        if (type.ResponseClass != ResponseClassType.Success)
            return false;
    }

    return true;
}
与君绝 2024-08-16 06:52:44

我曾使用 SQL Server 在客户端桌面无法发送邮件(通常出于安全原因)但服务器可以的情况下发送电子邮件。

I have used SQL Server to send e-mail in situations where the client desktop was not able to send mail (usually for security reasons) but the server could.

绝影如岚 2024-08-16 06:52:44

SmtpClient 在 .NET 4.0 中进行了修改,以便它可以通过发送 QUIT 消息来正确关闭连接。此外,在 unicode 编码和长行长度折叠方面的标准合规性也得到了显着改进,因此您应该会发现,如果您切换到 .NET 4.0,您的垃圾邮件分数会下降。 .NET 4.0 Beta 2 中提供了折叠和编码修复,但您必须等到 .NET 4.0 RC 才能修复 QUIT 消息。此外,SmtpClient 现在将实现 IDisposable,以便您可以在发送完消息后确定地关闭您的 smtp 连接。这篇博文详细介绍了已做出的一些改进,尽管它没有讨论 SmtpClient 上的 IDisposable(应该是该博客上某个时候描述该更改的另一篇博文): http://blogs.msdn.com/ncl/存档/2009/08/06/what-s-new-in-system-net-mail.aspx

SmtpClient was modified in .NET 4.0 so that it properly closes connections by sending a QUIT message. In addition, significant improvements were made to standards compliance with respect to unicode encoding and folding of long line lengths so you should find that your spam scores go down if you switch to .NET 4.0. The folding and encoding fixes shipped in .NET 4.0 Beta 2 but you'll have to wait until .NET 4.0 RC to get the QUIT message fix. In addition, SmtpClient will now implement IDisposable so that you can deterministically close your smtp connections when you are finished sending messages. This blog post details some of the improvements that have been made although it doesn't talk about IDisposable on SmtpClient (should be another blog post on that blog at some point that describes that change): http://blogs.msdn.com/ncl/archive/2009/08/06/what-s-new-in-system-net-mail.aspx

墨小墨 2024-08-16 06:52:44

Rebex Secure Mail 怎么样?

披露:我参与了这个库的开发。

What about Rebex Secure Mail?

Disclosure: I'm involved in development of this library.

复古式 2024-08-16 06:52:44

我对这些组件很满意:QuikSoft

I have been happy with these components: QuikSoft

兲鉂ぱ嘚淚 2024-08-16 06:52:44

对于符合标准且广泛的邮件工具套件(以及其他 IETF 标准),我多次发现 /n software 的 IP*Works 是一个很好的 API。我在传入和传出场景中都使用过它。对于传出场景,我将其用于大型邮件发送支持,在我当前的项目中,我将其用于大规模 IMAP 邮件检索,以大量使用传入客户支持邮箱。我从未遇到过任何合规问题(到目前为止一切顺利)。

该套件不仅仅支持 IMAP 和 SMTP。它可以在此处找到,考虑到您所得到的东西,我发现成本是相当可以承受的为了你的钱。

For a standards compliant and broad suite of mail tools (and other IETF standards) I have several times found /n software's IP*Works to be a good API. I've used it in both incoming and outgoing scenarios. For the outgoing scenario, I used it for large mail-out support, and on my current project I use it for large scale IMAP mail retrieval for heavy use incoming customer support mailboxes. I've never had any compliance issues (so far so good).

The suite supports much more than just IMAP and SMTP. It can be found here, and I've found the cost to be quite bearable considering what you get for your money.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文