Send an Email over SharePoint and .Net(Gmail):
public bool sendAnEmail(SPListItem item)
{
SPWeb thisWeb = item.ParentList.ParentWeb;
string subject = string.Empty;
string from = "test@Domain.co.in";
string toField = string.Empty;
string bodyText = string.Empty;
string cc = string.Empty;
string testCode = GetItemFieldvalue("testCode", item);
subject = "T Test Creation of [" + testCode + "] failed";
from = "Test@Domain.co.in";
string emailUsers = getListOf_JobEmail_NotificationUsers(thisWeb);
if (emailUsers !="")
{
toField = emailUsers;
}
else
{
toField = "test@domain.co.in";
}
string header = "Hi," + "<br />" + "<br />";
string body = "Test creation with testCode: " +testCode+" & Item ID: [" + item.ID + "] has been failed, please go through it and review." + "<br />" + " " + "<br />";
string footer = "Thanks ," + "<br />" + "\n (It is an auto generated an email do not reply.)";
bodyText = header + body + footer;
bool success = SPUtility.SendEmail(thisWeb, true, true, toField, subject, bodyText);
SendAnEmail_Net(toField, subject, bodyText);
return success;
}
public void SendAnEmail_Net(string toField, string subject, string bodyText)
{
SmtpClient client = new SmtpClient();
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("Test@gmail.com", "*****");
MailMessage mm = new MailMessage("Tets@gmail.com", toField, subject, bodyText);
mm.IsBodyHtml = true;
mm.BodyEncoding = UTF8Encoding.UTF8;
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
client.Send(mm);
}
No comments:
Post a Comment