protected void SendMail(string FromUserName, string ToUserName, string strContent, string strSubject)
{
try
{
string mstrContents;
//Retrives the contact mail ids
if (FromUserName != null && FromUserName.Trim() != "" && ToUserName != null && ToUserName.Trim() != "")
{
//Retrives the mailing contents
string strSiteName = DefaultSettings.SiteID;//ConfigurationManager.AppSettings["siteId"].ToString().Trim(); ;
SPSite site = new SPSite(strSiteName);
SPWeb web = site.OpenWeb();
string ToEmailid = web.AllUsers[ToUserName].Email;
string FromEmailId = ConfigurationManager.AppSettings["FromEmailId"].ToString().Trim(); ;
SmtpClient objSmtp = new SmtpClient(ConfigurationManager.AppSettings["SMTP"].ToString().Trim());
if (SPUtility.IsEmailServerSet(web))
{
MailAddress from = new MailAddress(FromEmailId);
MailAddress to = new MailAddress(ToEmailid);
MailMessage message = new MailMessage(from, to);
message.Subject = strSubject;
mstrContents = strContent;
message.Body = mstrContents;
objSmtp.Send(message);
}
site.Close();
site.Dispose();
web.Close();
web.Dispose();
}
}
catch (Exception ex)
{
string strError = ex.Message.ToString();
objErrorLog.WriteintoLogFile(ex.Message);
objErrorLog.WriteintoLogFile(ex.StackTrace);
}
}
No comments:
Post a Comment