19

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

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

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

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

4

8 回答 8

3

一种选择是MailKit。有很多功能,可以通过 a 可靠地取消发送CancellationToken,因此它不存在不遵守指定超时的问题SmtpClient在 NuGet 上也有很多下载。

甚至最近的文档也推荐它:

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

于 2016-09-08T12:05:49.070 回答
2

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

首先,您需要像这样引用交换网络服务: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;
}
于 2009-10-25T03:17:37.350 回答
1

Rebex Secure Mail怎么样?

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

于 2010-06-21T14:05:52.883 回答
1

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

于 2009-10-23T15:12:06.050 回答
1

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/archive/2009/08/06/what-s-new-in-system-net-mail.aspx

于 2009-12-15T10:07:09.133 回答
0

Castle Email.Sender 组件

于 2009-10-23T15:15:37.400 回答
0

我对这些组件很满意:QuikSoft

于 2009-10-23T15:19:30.950 回答
0

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

该套件支持的不仅仅是 IMAP 和 SMTP。可以在这里找到,而且我发现考虑到你的钱能得到什么,成本是可以承受的。

于 2009-10-25T21:40:22.927 回答