首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >System.Net.Mail替代

System.Net.Mail替代
EN

Stack Overflow用户
提问于 2009-10-23 15:07:12
回答 8查看 7.6K关注 0票数 20

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

最近,我遇到了与RFC违规有关的各种问题,以及其他问题,例如SmtpClient没有按照协议结束SMTP会话。这些问题中的每一个都会影响到垃圾邮件的高分,影响电子邮件的传递,所以我需要解决这些问题。

我想知道其他人是怎么解决这些问题的。人们是否已经开始使用第三部分组件,如果是的话,是哪一部分?

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

EN

回答 8

Stack Overflow用户

发布于 2016-09-08 12:05:49

另一种选择是MailKit。它有大量的特性,可以通过CancellationToken可靠地取消发送,因此它没有问题所在 of SmtpClient,因此它不遵守指定的超时。在NuGet上也有很多下载。

就连最近的文档也建议这样做:

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

票数 4
EN

Stack Overflow用户

发布于 2009-10-25 03:17:37

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

首先,您需要像这样引用exchange web服务:https://mail.yourwebserver.com/EWS/Services.wsdl

下面是一个示例:

代码语言:javascript
复制
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;
}
票数 2
EN

Stack Overflow用户

发布于 2009-10-23 15:12:06

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1614087

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档