Category: Development
Level: Beginner
You can send an email to all members of your SharePoint site using the following code:
SPSite mySite;
SPWeb currentWeb;
SPWeb currentWeb;
mySite = new SPSite(Url); //Url contains site URL
currentWeb = mySite.OpenWeb();
currentWeb = mySite.OpenWeb();
string sMemberName = "";
string strSubject = "";
string strBody = "";
string strSubject = "";
string strBody = "";
for (int i=0;i<currentWeb.Users.Count;i++)
{
{
sMemberName = currentWeb.Users.LoginName.ToString();
strSubject = "Testing";
strBody = "This is a test.";
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;
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 ...
}
}
msg.Subject = strSubject;
msg.Body = strBody;
msg.To = currentWeb.Users[_user].Email;
SmtpMail.Send(msg);
}
catch (Exception ex)
{
//Exception Handling Code ...
}
}
--SSA
No comments:
Post a Comment