send email in sharepoint 2007

Hi Folks,

if you are developing a webpart or any sharepoint customized feature,and you would like to send an email through your webpart or custom code,you can achieve this by 2 ways:

1) use normal .net classes to send email (System.Net.Mail namespace).
2) use below code:

using Microsoft.SharePoint.Utilities;

SPUtility.SendEmail(SPContext.Current.Web, false, false,
“to-address@mail.com”, “E-mail title”,
“E-mail body”);

this code will use the configuration of your sharepoint installation (SMTP server configuraiton),in the central administraiton tool.

the benefit of the second choice,you don’t need to store any other configuration for your SMTP server on your code,this code will directly use the sharepoint configuration and free your mind of SMTP configurations, if the sharepoint is configured propely and send email notification (throught workflows for example),then you code will work as well :).


hope this trick will help.

Regards,
Mostafa arafa

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>