Send Email in SharePoint(WSS 3.0 and MOSS 2007) Web Part 

Thursday, February 24, 2011 9:52:00 AM

Although you can technically send an email in a web part I would recommend against this as the default SPUtility.SendEmail method is synchronous which results in blocking and a slow page load while the email method is being processed/email is being sent. The asynchronous method to send Email found SmtpClient SendAsync is not available as an option in SPUtility.

Your next thought may be to use a MailMessage and SmtpClient which wont' work as ASP.NET pages in SharePoint don't support the Async="true" attribute.

MailMessage mm = new MailMessage();
mm.To.Add(ConfigurationManager.AppSettings["ToEmail"]);
mm.From = new MailAddress(this.txtEmail.Text,this.txtFullname.Text);
mm.Subject = ConfigurationManager.AppSettings["EmailSubject"];

SmtpClient smtp = new SmtpClient();
smtp.Host = ConfigurationManager.AppSettings["OutgoingMailServer"];
smtp.SendAsync(mm, null);

The accepted solution is to develop a SharePoint Event Receiver that sends an email asynchronously though ItemAdded that is attached to the List Instance or via Content Type so that all list instances will have an Event Receiver that send an email.

The main reason this is the accepted solution is that if you develop a web part that creates a list item and then sends an email notification after the list item has been added; if you add a list item manually the email notification won't be sent since this code is only found in your web part.

Out of the box SharePoint Designer workflow doesn't support use of an employee full name in a workflow email

Out of the box SharePoint Designer workflow doesn't support the use of an employee full name in a workflow email. Modifying the default out of hte box Date formatting is not supported either so a note is that you will have to either use the default date format or write/attain a Workflow Action to do date formating.

Taken from this article, you can add the full name to a workflow email or string for any other use by:

1. Install the SharePoint Designer Workflow action found here: http://www.codeplex.com/spdactivities

2. Go through the instructions in the InstallGuide.txt that came with the above download.

1. Extract all files in the arhive to a singe location.

2. Run setup.exe

3. Go to Central Administration -> Application Management -> Manage Web Application Features and activate the feature for desired web applications (usually it's Sharepoint - 80 or Sharepoint - 443).

3. After you have enabled this Feature above then you must close SharePoint Designer and then open your site again and you will find new Custom Actions.

4. Build a Dynamic String to store the account name

5. Add the Lookup site user property action

6. Specify LinkTitle as the property.

7. Specify the variable you created in #4 above as the user

8. Create a new variable called employeefullname

9. Add the employeefullname as workflow data in your email action.

http://sharepointapplied.com/2009/01/08/get-full-name-in-sharepoint-designer-workflow/

Comments are closed on this post.