none
Sending mails in workflow. +VS 2010

    Question

  • I have a state machine workflow that works as follows

    1) On creating an item in a list a workflow gets started, I am assigning the task to a person programmatically

    like

    createTask1_TaskProperties1.AssignedTo = GetDepartmentOwner(department, url);

    I need to send a mail to the above assigned person and the guy who created the item.

    Again if the person who was assigned the task mark the status as "Resolved". A mail should be sent to the person who created it..

    I am using Visual studio 2010, state machine workflow

    Wednesday, January 05, 2011 7:48 AM

Answers

  • Hi SKPUTHER

    You can use SendEmail activity or use SpUtility.SendEmail like following example

    createTask1_TaskProperties1.AssignedTo = GetDepartmentOwner(department, url);

    SPUtility.SendEmail(this.workflowProperties.Web, true, true, "myemail@mail.com", "my subject", "my body", true);

    More Information

    Send E-mail Activity Sample

    SPUtility .SendEmail Method

    Note: you need aslo to Configure outgoing e-mail before sending emails to the users, see the below article

    Configure outgoing e-mail (SharePoint Server 2010)

    Regards.


    Ahmed Naji SharePoint Geek
    MCP|MCTS
    My Blog | DotnetFinder
    Wednesday, January 05, 2011 9:28 AM
  • Hi,

    You have three options to send email from the workflow:-

    1) SendEmail workflow activity

    http://msdn.microsoft.com/en-us/library/ms742097(VS.90).aspx

    2) SPUtility.SendEmail(param......) method

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility.sendemail.aspx

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

    3) .Net SMTP API

    To use any of above method, you make sure that Outgoing Email is configured.

    • If you are using SendEmail activity make sure all the properties like From, To etc. should be initialized before workflow control trigger SendEmail activity.
    • If you are using SMTP, you set the Host address as follow:
     SmtpClient smtpClient = new SmtpClient();
     smtpClient.Host = workflowProperties.TaskList.ParentWeb.Site.WebApplication.
        OutboundMailServiceInstance.Server.Address;
    
    
    
    I hope one of above way is worked for you.
    Wednesday, January 05, 2011 11:02 AM
  • You should check the following setting for your workflow association:-

    ListSettings-> WorkflowSettings-> "Click on your workflow to open workflow association configuration".

    Here your should check the "Specify what you want to happen when a workflow is initiated:" section "Send Email Message" check box should be checked.

    If this configuration is not worked for you. You try to reattach the another task list with workflow.

    Wednesday, January 05, 2011 11:44 AM

All replies

  • Hi SKPUTHER

    You can use SendEmail activity or use SpUtility.SendEmail like following example

    createTask1_TaskProperties1.AssignedTo = GetDepartmentOwner(department, url);

    SPUtility.SendEmail(this.workflowProperties.Web, true, true, "myemail@mail.com", "my subject", "my body", true);

    More Information

    Send E-mail Activity Sample

    SPUtility .SendEmail Method

    Note: you need aslo to Configure outgoing e-mail before sending emails to the users, see the below article

    Configure outgoing e-mail (SharePoint Server 2010)

    Regards.


    Ahmed Naji SharePoint Geek
    MCP|MCTS
    My Blog | DotnetFinder
    Wednesday, January 05, 2011 9:28 AM
  • Hi,

    You have three options to send email from the workflow:-

    1) SendEmail workflow activity

    http://msdn.microsoft.com/en-us/library/ms742097(VS.90).aspx

    2) SPUtility.SendEmail(param......) method

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility.sendemail.aspx

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

    3) .Net SMTP API

    To use any of above method, you make sure that Outgoing Email is configured.

    • If you are using SendEmail activity make sure all the properties like From, To etc. should be initialized before workflow control trigger SendEmail activity.
    • If you are using SMTP, you set the Host address as follow:
     SmtpClient smtpClient = new SmtpClient();
     smtpClient.Host = workflowProperties.TaskList.ParentWeb.Site.WebApplication.
        OutboundMailServiceInstance.Server.Address;
    
    
    
    I hope one of above way is worked for you.
    Wednesday, January 05, 2011 11:02 AM
  • HI Ahmed

    Thanks!

    I am doing like this

    createTask1_TaskProperties1.AssignedTo = GetDepartmentOwner(department, url);

    createTask1_TaskProperties1.EmailBody =

     

     

     

    My question is how will I get the Email ID of the person who created the request? is there any easy way?

    will it work?

    Guid IdcreatedBy= workflowProperties.TaskList.Fields["Created By"].Id;

     

     

    string CreatedBy= (string)(onTaskChanged1_AfterProperties1.ExtendedProperties[createdBy]);

    "New Help desk request posted!";

    createTask1_TaskProperties1.SendEmailNotification =

    true;
    Wednesday, January 05, 2011 11:03 AM
  • HI Ahmed

    Thanks!

    Please ignore previous one .

    I am doing like this

    createTask1_TaskProperties1.AssignedTo = GetDepartmentOwner(department, url);

    createTask1_TaskProperties1.EmailBody ="New Help desk request posted!";
    createTask1_TaskProperties1.SendEmailNotification =true;

     

    My question is how will I get the Email ID of the person who created the request? is there any easy way?

    will it work?


    Guid IdcreatedBy= workflowProperties.TaskList.Fields["Created By"].Id;


    string CreatedBy= (string)(onTaskChanged1_AfterProperties1.ExtendedProperties[createdBy]);

    Wednesday, January 05, 2011 11:22 AM
  • You should check the following setting for your workflow association:-

    ListSettings-> WorkflowSettings-> "Click on your workflow to open workflow association configuration".

    Here your should check the "Specify what you want to happen when a workflow is initiated:" section "Send Email Message" check box should be checked.

    If this configuration is not worked for you. You try to reattach the another task list with workflow.

    Wednesday, January 05, 2011 11:44 AM