views:

487

answers:

7

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

A: 

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.

Doug L.
A: 

Castle Email.Sender component?

Krzysztof Koźmic
A: 

I have been happy with these components: QuikSoft

Ray
+1  A: 

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;
}
Nathan Palmer
A: 

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.

Andrew Matthews
+1  A: 

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

Jeff Tucker
A: 

What about Rebex Secure Mail?

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

Martin Vobr