Answered SendEmail activity problem

  • Thursday, February 07, 2008 11:48 PM
     
     

         I am using a SendEmail activity in a SharePoint workflow just before the workflow completes. It always gives me this text in the WorkflowHistory , and the email cannot be sent out.

     

           The e-mail message cannot be sent. Make sure the outgoing e-mail settings for the server are configured correctly.

     

           I am sure that the outgoing email settings in the Central Administration has been configured, because the CreateTask activity can actually send out task email. I gave values to the To, From, Subject in the code, and bind the Body to a workflow field. The CorrelationToken is set to the workflowToken. But it still doesn't work. Is there anything special I need to do?

     

     Thanks.

     

Answers

All Replies

  • Friday, February 08, 2008 2:18 AM
     
     
    In theory you don't need to do anything special to make SendEmail work. It's probably worth checking the ULS logs to see if you can get a bit more info on what's actually going wrong.

    That said, I've had enough difficulties with SendEmail that I usually use a custom code activity and the System.Net.Mail class instead.
  • Friday, February 08, 2008 6:02 PM
     
     

    Thanks. I think I will need to go sameway.

     

    I have seen several complains in other places. Really hope Microsoft someday could give a detailed document on its sharepoint classes and class members instead of just a single sentence.

     

     

     

  • Wednesday, March 05, 2008 7:05 AM
     
     Answered

    Hey I had this problem to.

     

    Check out my post at http://spschris.blogspot.com/2008/03/e-mail-message-cannot-be-sent-make-sure.html

     

    All you need to do is map global properties/fields in the SendEmail Activity properties window.  Then where your setting your properties programatically currently, just set the global fields value instead.  You can reuse these fields/properties over and over again for each workflow activity, unless you have simultaneous activities running in parallel.

     

  • Wednesday, March 05, 2008 1:57 PM
     
     
    Maybe this helps:
    I'm sending email in a custom VSTO2005 workflow, using this code:
               SmtpClient client = new SmtpClient();
               client.Host = SmtpServer;
               client.Port = 25;
               client.DeliveryMethod = SmtpDeliveryMethod.Network;
    
               MailMessage myMailMessage = new MailMessage();
               myMailMessage.From = new MailAddress(fromEmail);
               myMailMessage.Subject = emailSubject;
               myMailMessage.Body = emailMessage;
               myMailMessage.To.Add(new MailAddress(toEmail));
               client.Send(myMailMessage);
    
    (having declared fromEmail, emailSubject, emailMessage and toEmail as strings somewhere before...)
    Hope this helps you somehow?
  • Wednesday, March 05, 2008 10:03 PM
     
     

    I found that the SPUtility.SendEmail( ) from the Microsoft.Sharepoint.Utilites namespace works best.  You only need one line of code, that's it:

    Code Snippet

     

    Using Microsoft.Sharepoint.Utilities;

     

    SPUtility.SendEmail(this.workflowProperties.Web, true, false, contact.EmailAddress, "Task Completed", "Test Email");

     

     

     

     

    Syntax:

    SendEmail(SPWeb Web, bool fAppendHtmlTag, bool fHtmlEncode, string to, string subject, string htmlbody)

     

    That way, you are assured you are using the Sharepoint outgoing email settings.

     

    Bryant

  • Thursday, March 06, 2008 7:50 AM
     
     

    Bryant...

    You're the best :-)

    I've been looking for that kind of function for a very very long time!

    Thx man. It's obviously much easier!

     

  • Thursday, March 06, 2008 1:05 PM
     
     

    Your welcome.  Just FYI, if you declare a string first and use it in the SendEmail method, you can easily send a custom HTML email message.  I have done this to send some fairly unique and detailed emails.

     

    Bryant

     

  • Tuesday, March 11, 2008 10:08 PM
     
     

     

    Thank you Chris. This was the answer.

    I did verify this does seem to be a nesting problem. My SendMail was inside an ifelse inside a CAG. When I moved it outside it worked. Your blog provided the answer.

    Thank you very much!!!!

  • Wednesday, July 15, 2009 12:56 PM
     
     
    Hi.

    Thanks a ton....for this answer.......

    jr software programmer