SharePoint User Group UK

Share the knowledge!

Welcome to SharePoint User Group UK Sign in | Join | Help
in
Home Blogs Forums Photos Files Roller

Microsoft.SharePoint.WorkflowActions.SendEmail

Last post 06-26-2008, 5:10 PM by Cimares. 4 replies.
Sort Posts: Previous Next
  •  06-25-2008, 2:16 PM 11682

    Microsoft.SharePoint.WorkflowActions.SendEmail

    Hi

     

    I was wondering if anyone knew if it was possible to use:

    Microsoft.SharePoint.WorkflowActions.SendEmail

    in code.

    basically, I am writing a custom workflow in VS2008. If you drag the workflow object "SendEmail" and generate its handler you can use the method stub created to set the properties of the email that is to be sent.

    In my workflow after most tasks are completed, an email needs to be sent. So I am basically, wondering if I could code it in other methods as opposed to having to include several sendEmail objects and code each method for it.

    I have googled this and I can't find out if I can do this or not

     

    Many thanks

  •  06-25-2008, 2:42 PM 11685 in reply to 11682

    Re: Microsoft.SharePoint.WorkflowActions.SendEmail

    Just spent 2 days fiddling with SendEmail activity.

    It is a bit of a pain in the bum.

    I ended up writing my own custom activity using System.Net.Mail ie...

    I had loads of issues with the correlation token in the Sendactivity.

    Ask me question if you need to.

    Had a lot of help from a guy called Alex. thanks Alex

        public partial class MyEmailSender: SequenceActivity
        {
            public string EmailSubject = string.Empty;
            public int ListItemIdTolinkTo = 0;
            public Guid MainWorkflowPropertiesTaskListId;
            public string MainWorkflowPropertiesWebURL = string.Empty;
            public string TaskAssignedToEmail = string.Empty;
            public Acres.DataContracts.BusinessCaseContentType FullCase;

            public MyEmailSender()
            {
                InitializeComponent();
            }

            private void sendEmail_ExecuteCode( object sender, EventArgs e ) {
                try {
                    MailMessage message = new MailMessage();

                    message.From = new MailAddress( ConfigurationManager.AppSettings[ "WFFromEmailAdress" ].ToString() );
                    message.To.Add( TaskAssignedToEmail );
                    message.Subject = "A " + ConfigurationManager.AppSettings[ "ProjectFinAppWorkflow" ].ToString() + " has been assigned to you.";
                    message.Body = InternalUtilities.EmailBodyCreation( FullCase );
                    message.IsBodyHtml = true;
                    SmtpClient client = new SmtpClient( ConfigurationManager.AppSettings[ "SmtpClientserver" ].ToString() );

                    string taskurl = returnTaskUrls(  ListItemIdTolinkTo.ToString() );

                    message.Body += taskurl; // Add taks edit link URL to end of email

                    client.Send( message );

                } catch ( SmtpException smtpEx ) {
                    //myLog.WriteEntry( "Emails from " + ConfigurationManager.AppSettings[ "WorkflowSystemName" ].ToString() + " could not be sent:" + smtpEx.Message );
                }
            }

            private string returnTaskUrls( string ListItemId ) {

                string weburl = MainWorkflowPropertiesWebURL;
                string taskUrl = ConfigurationManager.AppSettings[ "PathToTaskForm" ].ToString();
                string listid = MainWorkflowPropertiesTaskListId.ToString();
                string fulltaskUrl = weburl + taskUrl + listid + "&ID=" + ListItemId;
                string htmlTaskLink = "<font size=\"small\"><a href=" + "\"" + fulltaskUrl + "\"" + ">Edit This Task</a></font>";

                return htmlTaskLink;
            }



    Regards
    Russell McCloy
    http://russellmccloy.blogspot.com/
  •  06-25-2008, 4:39 PM 11693 in reply to 11682

    Re: Microsoft.SharePoint.WorkflowActions.SendEmail

    As russell pointed out its pretty simple to do it in code yourself. Just put it in a library you can reuse in other projects.

    Heres another example

    public static void SendMail(SPWeb web, string from, string to, string subject, string body)

    {

    MailMessage message = new MailMessage(from,to);

    message.Subject = subject;

    message.Body = body;

    message.IsBodyHtml = true;

    SmtpClient client = new SmtpClient(web.Site.WebApplication.OutboundMailServiceInstance.Server.Name);

    client.Send(message);

    }

     

    Colin Byrne

    http://blogs.flexnetconsult.co.uk/colinbyrne

  •  06-25-2008, 5:18 PM 11695 in reply to 11693

    Re: Microsoft.SharePoint.WorkflowActions.SendEmail

    Brilliant, thanks guys!
  •  06-26-2008, 5:10 PM 11745 in reply to 11695

    Re: Microsoft.SharePoint.WorkflowActions.SendEmail

    Richie, I wrote a short blog post on how to use the SPUtility.SendEmail method that might also be of use to you, But only if you don't want to send attachments!

    Using this method has the advantage of letting SharePoint control all of the SMTP side of things without having to pull out the data from the Config object.

    http://www.myfatblog.co.uk/?p=79

    Paul.


    www.myfatblog.co.uk
    twitter.com/@cimares
    MCTS: WSS 3.0
    MCTS: MOSS 2007
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems