Email Queue issue

Mak Hattalli asked on January 21, 2015 06:53

Hi Brenden Kehren, This is a custom method to sending email.please let me know that issue, ASAP.

public void SendMail(string from, string to, string location, string emailtext) {

    // Prepare the macro resolver
    ContextResolver resolver = ContextResolver.CreateContextChild();
    EmailMessage message = new EmailMessage();
    message.EmailFormat = EmailFormatEnum.Html;

    message.From = from;
    message.Recipients = to;

    // Get current css stylesheet
    string styleSheet = GetCssFileLink();
    if (!String.IsNullOrEmpty(styleSheet))
    {
        styleSheet = URLHelper.MakeLinksAbsolute(styleSheet);
    }

    // resolve EmailSubject here
    message.Subject = "Company details Details";//resolver.ResolveMacros(subject);
    // resolve EmailTemplate, wrap to HTML code and add the CSS files
    //message.Body = "<html><head>" + styleSheet + "</head><body class=\"EmailBody\">" + resolver.ResolveMacros(txtmessage.Text) +  resolver.ResolveMacros(BlogPageUrl) + "</body></html>";
    message.Body = "<html><head>" + styleSheet + "</head><body class=\"EmailBody\">" + resolver.ResolveMacros("Company Details") + "<br/><h2>" + resolver.ResolveMacros(location) + "</h2><div  class=\"EmailBody\">" + resolver.ResolveMacros(emailtext) + "</div><p>" + resolver.ResolveMacros("http://basilglobal.com/") + "</p></body></html>";
    // check recipients

    if ((message.Recipients != null) && (message.Recipients.Trim() != ""))
    {
        //try
        //{
        EmailSender.SendEmail(CMSContext.CurrentSiteName, message);
        //}
        //catch (Exception ex)
        //{
        //}
    }
}

Recent Answers


Brenden Kehren answered on January 21, 2015 13:49

Based on your code it looks like you might want to check if your "from" address is null or empty as well. An easy way to do this is:

if(string.IsNullOrEmpty(to) || string.IsNullOrEmpty(from))
{
    // one of your addresses is empty so don't send it
}
else
{
    // go ahead and send it
}
1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.