none
SmtpClient.Send() and SmtpClient.SentTaskAsync() Subject encoding RRS feed

  • Question

  • Hi.

    I'm trying to send Email messages using SmtpClient class. Previously was with use of Send() method, and subject encoding was working fine, for example:

    Subject: =?utf-8?B?Tm90aWZpY2FjacOzbiBkZSBFdmFsdWFjacOzbiBET1cgUVVJ?= =?utf-8?B?TUlDQSBNRVhJQ0FOQSBTQSBERSBDVg==?=

    but now we need to send some more mail messages and meanwhile make some other task. So we change the implementation for make use of SendTaskAsync() method but after that subject encoding changed to

    Subject: Notificación de Evaluación DOW QUIMICA MEXICANA SA DE CV

    For testing we use the same message and send with both methods with same results. We tried setting message SubjectEncoding property to utf8, ISO-8859-1 and other but nothing changes with SendTaskAsync method.

    What is necessary to modify when using one method or another?

    ¡Thank You!




    • Edited by Carlos Ayala Wednesday, February 25, 2015 11:57 PM
    Wednesday, February 25, 2015 11:28 PM

Answers

  • Thank you jdweng.

    But i think you're not getting the point here. The problem is not what happens in backstage from one method or another.

    As I said before, we are doing some other task while many messages are sending. And FYI, every message have one or more attachments, so the 1000 bytes that you think are not real.

    The point of my question is to know why SendTaskAsync behaves diferent to Send method in words of subject encoding.

    BTW, now i'm using Send method with Task.Run and problem solved.

    Thank you!

    Saturday, February 28, 2015 7:48 PM

All replies

  • There shouldn't be any difference.  See Socket Async example below.  If this doesn't help then post some of your code.  For sending, I don't think Async really has any advantages over the Send() method.  Only the receive Async provides any improvements.  The send message handshaking is performed in the Ethernet card adapter.  All the Asyc Send does is moves the message from the VS application to the card adapter.

    https://msdn.microsoft.com/en-us/library/bew39x2a(v=vs.110).aspx


    jdweng

    Thursday, February 26, 2015 12:47 AM
  • There are some problems with subject encoding — https://social.msdn.microsoft.com/Forums/vstudio/en-US/4d1c1752-70ba-420a-9510-8fb4aa6da046 — however they are not caused by asynchronous operations. The workaround is to use a different encoding. Though if your problem occurs only in asynchronous case, then maybe you can use the old working code, but invoked inside a separate thread.

    Thursday, February 26, 2015 6:46 AM
  • In my case, is necesary to use async because we are not sending only one mail. And another tasks need to be performed menwhile. Thank you!
    • Edited by Carlos Ayala Saturday, February 28, 2015 4:37 PM
    Saturday, February 28, 2015 4:37 PM
  • I have tryed with many encoding with no success. Looks like if SendTaskAsync method is not taking subject encoding.

    I will use Send method instead but inside a Task.Run method.

    Thank you!

    Saturday, February 28, 2015 4:39 PM
  • The send is only moving the size of you message ( a few 1000 bytes) which take very little time. It is not worth the effort to setup an async method which could delay the message 100-200msec.

    jdweng

    Saturday, February 28, 2015 5:34 PM
  • Thank you jdweng.

    But i think you're not getting the point here. The problem is not what happens in backstage from one method or another.

    As I said before, we are doing some other task while many messages are sending. And FYI, every message have one or more attachments, so the 1000 bytes that you think are not real.

    The point of my question is to know why SendTaskAsync behaves diferent to Send method in words of subject encoding.

    BTW, now i'm using Send method with Task.Run and problem solved.

    Thank you!

    Saturday, February 28, 2015 7:48 PM