This resource has not currently been approved, and is not currently linked to from our directory of resources. It is being displayed here for preview by the author and moderators only.
Page1
You can send an email to all members of your SharePoint site using the following code:
SPSite mySite;
SPWeb currentWeb;
mySite = new SPSite(Url); //Url contains site URL
currentWeb = mySite.OpenWeb();
string sMemberName = "";
string strSubject = "";
string strBody = "";
for (int i=0;i<currentWeb.Users.Count;i++)
{
sMemberName = currentWeb.Users[i].LoginName.ToString();
strSubject = "Testing";
strBody = "This is a test.";
SendMail(currentWeb,currentWeb.Users[sMemberName].ToString() , strSubject, strBody);
}
//SendMail Function
public void SendMail(SPWeb currentWeb, string _user,string strSubject, string strBody)
{
MailMessage msg;
try
{
SmtpMail.SmtpServer = "smtp.yourserver.com";
msg = new MailMessage();
msg.BodyFormat = MailFormat.Html;
msg.From = currentWeb.Author.Email;
msg.Subject = strSubject;
msg.Body = strBody;
msg.To = currentWeb.Users[_user].Email;
SmtpMail.Send(msg);
}
catch (Exception ex)
{
//Exception Handling Code ...
}
}
Do not forget to add Microsoft.System.Web.DLL in references. Add following code at the top of your page:
using Microsoft.System.Web;
You can also use third party email components. <a href="http://www.aspemail.com">aspemail.com</a> is an example. It is an excellent emailing component that you can use in your .NET applications including SharePoint's.