locked
workflow to be sent on specifc day, ervery week. RRS feed

  • Question

  • Hi,

    i want to create a workflow in SharePoint designer 2010,

    the action is to be sent every week on specific day and time by email ,

    this email will have an attachment of a info path form.

    i am just fresh, so i depend on you, please help.

    thanks.

    Tuesday, May 8, 2012 11:28 AM

All replies

  • Hi Osman,

    In order to send email every week on specific day and time, you need to create a timer job by visual studio. In order to write code of the timer job, you can refer to this document.

    In order to send email by the timer job, you can use workflow out of the box actions. But you cannot send email with attachments. Third party custom actions like this can help you to send email with list attachments. Then you can start the workflow in timer job like this:

    //You can get the guid of the workflow by going to the page where you start the workflow and copying the templateId form the url.
    SPWorkflowAssociation wrkFl = list.WorkflowAssociations[new Guid("2f9501e0-6762-4c0d-b092-9ea765a3cd7f")];
    siteCollection.WorkflowManager.StartWorkflow(item, wrkFl, wrkFl.AssociationData, true);

    Sending email by code is also feasible:

    public class SendEmailJobDef
            : SPJobDefinition
        {
            private SmtpClient LoadSmtpInformation()
            {
    //Get the smtpServer of the site
                string smtpServer = SPAdministrationWebApplication.Local.OutboundMailServiceInstance.Server.Address;
                SmtpClient client = new SmtpClient(smtpServer);
                client.Credentials = new System.Net.NetworkCredential("Domain\UserName", "Password");
                return client;
            }
            public override void Execute(Guid targetInstanceId)
            {
                SPSite site=new SPSite("http://yoursite");
                //Get the list item
                SPList list= site.OpenWeb().Lists["leave application"];
                SPListItem item=list.GetItemById(5);
                LoadSmtpInformation().Send(BuildMailMessage(item));
            }
            private System.Net.Mail.MailMessage BuildMailMessage(SPListItem item)
            {
                MailMessage message = new MailMessage();
                SPList list = item.ParentList;
                 
                message.From = new MailAddress(SPAdministrationWebApplication.Local.OutboundMailSenderAddress.ToString());
                message.To.Add(new MailAddress("test@example.com"));//email address
                message.IsBodyHtml = true;
                message.Body = "Hi there, check out the attachment";
                message.Subject = "Sent Attachment";
                 
                for (int attachmentIndex = 0; attachmentIndex < item.Attachments.Count; attachmentIndex++)
                {
                    string url = item.Attachments.UrlPrefix + item.Attachments[attachmentIndex];
                    SPFile file = list.ParentWeb.GetFile(url);
                    message.Attachments.Add(new Attachment(file.OpenBinaryStream(), file.Name));
                }
             
                return message;
            }
    }

    Thanks,


    Lambda Zhao

    TechNet Community Support

    Wednesday, May 9, 2012 6:55 AM