How to send HTML emails asynchronously?

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
5/28/2011 10:06:15 PM
Gravatar
Total Posts 9

How to send HTML emails asynchronously?

Hi All,

From code, I would like to send a few html emails asynchronously, using SMTP.

The EmailMessageTask class could be used, except it's only allowing plain text emails. The code snippet below, taken from EmailMessagesTask.cs, shows that Email.Send() is not using html (second to last parameter is false).

public class EmailMessageTask
{
...
private void RunTask()
{
  ...
  Email.Send(
   smtpSettings,
   emailFrom,
   emailFromAlias,
   emailReplyTo,
   emailTo,
   emailCc,
   emailBcc,
   subject,
   textBody,
   false,
   emailPriority);
  ...
}
...
}

We could expose UseHTML as a public property on EmailMessageTask and then pass that as the second to last parameter. For example:

public class EmailMessageTask
{
...
private bool useHTML = false;
...
public bool UseHTML
{
  get { return useHTML; }
  set { useHTML = value; }
}
...
private void RunTask()
{
  ...
  Email.Send(
   smtpSettings,
   emailFrom,
   emailFromAlias,
   emailReplyTo,
   emailTo,
   emailCc,
   emailBcc,
   subject,
   textBody,
   useHTML,
   emailPriority);
  ...
}
...
}

Could we implement this, or is there an existing alternative in mojoPortal?

Kind regards,

Jonas

P.S

Another option would be to not use EmailMessageTask, instead have the Email class indirectly expose SmtpClient's SendAsync() method (see SmtpClient Class). This option would require more work.

5/29/2011 12:22:12 PM
Gravatar
Total Posts 18439

Re: How to send HTML emails asynchronously?

I've added the UseHtml and HtmlBody properties on EmailMessageTask. This is in the source code repository now.

Best,

Joe

5/29/2011 4:49:25 PM
Gravatar
Total Posts 9

Re: How to send HTML emails asynchronously?

Great. Thanks Joe!

You must sign in to post in the forums. This thread is closed to new posts.