string mailSubjects = string.Empty;
string MailUserName = string.Empty;
string MailPassword = string.Empty;
string smtpClientHost = string.Empty;
string MailFrom = string.Empty;
string email = string.Empty;
Int32 SMTPPort = 35;
string MailFromName = string.Empty;
MailFrom = "alertwww@ibtechnology.com";
MailUserName = "alertwww@ibtechnology.com";
MailPassword = "noida@123";
smtpClientHost = "10.11.200.225";
SMTPPort = 35;
MailFromName = "Compliance";
mailSubjects = "IA | ACCELERATOR ~ Reminder mail";
public SPUser ReturnUserName(string siteurl, string AuditOwnerName)
{
SPUser ownerName = null;
using (SPSite oSpSite = new SPSite(siteurl))
{
using (SPWeb oSpWeb = oSpSite.OpenWeb())
{
ownerName = oSpWeb.EnsureUser(AuditOwnerName.Trim('#'));
return ownerName;
}
}
}
public void forwardtoAuditOwner(string siteurl,string OwnerName, DataTable dtAuditorOwner,string mailSubjects)
{
SPUser ownerName = null;
string OwnerEmail = string.Empty;
using (SPSite oSpSite = new SPSite(siteurl))
{
using (SPWeb oSpWeb = oSpSite.OpenWeb())
{
string Owner = string.Empty;
ownerName = oSpWeb.EnsureUser(Convert.ToString(OwnerName));
IAAEmail objIAAEmail = new IAAEmail();
objIAAEmail.MailSubject = mailSubjects;
//objIAAEmail.ToMailAddress = "ved.p1@ibtechnology.com";
objIAAEmail.ToMailAddress = Convert.ToString(ownerName.Email);
if (Convert.ToString(ownerName.LoginName.Split('|')[0].Split('.')[1]) == "w")
{
Owner = ownerName.LoginName.Split('|')[1].Split('\\')[1];
}
else
{
Owner = ownerName.LoginName.Split('|')[2];
}
StringBuilder strbuilder = new StringBuilder();
strbuilder.Append(
"<table width='100%' border='0' style='border:0px solid #ccc; font-family:'arial'; font-size:12px;' cellpadding='0' cellspacing='10'>"
+ "<tr>Dear " + Convert.ToString(Owner) + " , " + "</tr>"
+ "<tr></tr>"
+ "<tr>The status of the Completion of recommendation is as follows:</tr>");
strbuilder.Append("<tr><td><table width='100%' border='1' style='border:1px solid #ccc; font-family:'Calibri'; font-size:11px;' cellpadding='0' cellspacing='0'>"
+ "<tr>"
+ "<td width='30%' colspan='2' style='text-align:center'></td>"
+ "<td width='55%' colspan='4' style='text-align:center'>Recommendations pending with Owners</td>"
+ "<td width='15%' style='text-align:center'>Recommendations Pending for your approval</td>"
+ "</tr>"
+ "<tr>"
+ "<td width='15%' style='text-align:center'>Audit Name</td>"
+ "<td width='15%' style='text-align:center'>Audit ID</td>"
+ "<td width='15%' style='text-align:center'>Overdue/Delayed</td>"
+ "<td width='15%' style='text-align:center'>Due in next 30 days</td>"
+ "<td width='15%' style='text-align:center'>Due beyond 30 days</td>"
+ "<td width='10%' style='text-align:center'>Total</td>"
+ "<td width='15%' style='text-align:center'>Total</td>"
+ "</tr>");
if (dtAuditorOwner != null && dtAuditorOwner.Rows.Count > 0)
{
foreach (DataRow _row in dtAuditorOwner.Rows)
{
if (Convert.ToString(_row["RTotal"]) != "0")
{
strbuilder.Append("<tr><td width='15%' style='text-align:center'>");
strbuilder.Append(_row["AuditID"]);
strbuilder.Append("</td>");
strbuilder.Append("<td width='15%' style='text-align:center'>");
strbuilder.Append(_row["AuditName"].ToString());
strbuilder.Append("</td>");
strbuilder.Append("<td width='15%' style='text-align:center'>");
strbuilder.Append(_row["ODRecommendation"].ToString());
strbuilder.Append("</td>");
strbuilder.Append("<td width='15%' style='text-align:center'>");
strbuilder.Append(_row["Dueinnext30days"].ToString());
strbuilder.Append("</td>");
strbuilder.Append("<td width='15%' style='text-align:center'>");
strbuilder.Append(_row["Duebeyond30days"].ToString());
strbuilder.Append("</td>");
strbuilder.Append("<td width='10%' style='text-align:center'>");
strbuilder.Append(_row["RTotal"].ToString());
strbuilder.Append("<td width='15%' style='text-align:center'>");
strbuilder.Append(_row["RecPendingApproval"]);
strbuilder.Append("</td>");
strbuilder.Append("</tr>");
}
}
}
strbuilder.Append("</table></td></tr>");
strbuilder.Append("<tr>Please click on the " + " <a href=" + siteurl + "/_layouts/EY.IAA.Login/LoginPage.aspx>link</a>" + " to review & take action on the same</tr>"
+ "<tr>Regards<br/>Admin</tr>"
+ "</table>");
objIAAEmail.MailBody = strbuilder.ToString();
MailSend(objIAAEmail, oSpWeb);
}
}
}
public bool MailSend(IAAEmail objIAAEmail, SPWeb oWeb)
{
bool result = false;
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
if (!string.IsNullOrEmpty(Convert.ToString(objIAAEmail)))
{
MailMessage message = new MailMessage(MailFrom, objIAAEmail.ToMailAddress);
message.Subject = Convert.ToString(objIAAEmail.MailSubject);
message.Body = Convert.ToString(objIAAEmail.MailBody);
message.IsBodyHtml = true;
NetworkCredential nc = new NetworkCredential(MailUserName, MailPassword);
SmtpClient smtpClient = new SmtpClient(smtpClientHost);
smtpClient.Port = SMTPPort;
smtpClient.Credentials = nc;
smtpClient.Send(message);
message.Dispose();
result = true;
}
});
return result;
}
catch (Exception ex)
{
throw ex;
}
}
string MailUserName = string.Empty;
string MailPassword = string.Empty;
string smtpClientHost = string.Empty;
string MailFrom = string.Empty;
string email = string.Empty;
Int32 SMTPPort = 35;
string MailFromName = string.Empty;
MailFrom = "alertwww@ibtechnology.com";
MailUserName = "alertwww@ibtechnology.com";
MailPassword = "noida@123";
smtpClientHost = "10.11.200.225";
SMTPPort = 35;
MailFromName = "Compliance";
mailSubjects = "IA | ACCELERATOR ~ Reminder mail";
public SPUser ReturnUserName(string siteurl, string AuditOwnerName)
{
SPUser ownerName = null;
using (SPSite oSpSite = new SPSite(siteurl))
{
using (SPWeb oSpWeb = oSpSite.OpenWeb())
{
ownerName = oSpWeb.EnsureUser(AuditOwnerName.Trim('#'));
return ownerName;
}
}
}
public void forwardtoAuditOwner(string siteurl,string OwnerName, DataTable dtAuditorOwner,string mailSubjects)
{
SPUser ownerName = null;
string OwnerEmail = string.Empty;
using (SPSite oSpSite = new SPSite(siteurl))
{
using (SPWeb oSpWeb = oSpSite.OpenWeb())
{
string Owner = string.Empty;
ownerName = oSpWeb.EnsureUser(Convert.ToString(OwnerName));
IAAEmail objIAAEmail = new IAAEmail();
objIAAEmail.MailSubject = mailSubjects;
//objIAAEmail.ToMailAddress = "ved.p1@ibtechnology.com";
objIAAEmail.ToMailAddress = Convert.ToString(ownerName.Email);
if (Convert.ToString(ownerName.LoginName.Split('|')[0].Split('.')[1]) == "w")
{
Owner = ownerName.LoginName.Split('|')[1].Split('\\')[1];
}
else
{
Owner = ownerName.LoginName.Split('|')[2];
}
StringBuilder strbuilder = new StringBuilder();
strbuilder.Append(
"<table width='100%' border='0' style='border:0px solid #ccc; font-family:'arial'; font-size:12px;' cellpadding='0' cellspacing='10'>"
+ "<tr>Dear " + Convert.ToString(Owner) + " , " + "</tr>"
+ "<tr></tr>"
+ "<tr>The status of the Completion of recommendation is as follows:</tr>");
strbuilder.Append("<tr><td><table width='100%' border='1' style='border:1px solid #ccc; font-family:'Calibri'; font-size:11px;' cellpadding='0' cellspacing='0'>"
+ "<tr>"
+ "<td width='30%' colspan='2' style='text-align:center'></td>"
+ "<td width='55%' colspan='4' style='text-align:center'>Recommendations pending with Owners</td>"
+ "<td width='15%' style='text-align:center'>Recommendations Pending for your approval</td>"
+ "</tr>"
+ "<tr>"
+ "<td width='15%' style='text-align:center'>Audit Name</td>"
+ "<td width='15%' style='text-align:center'>Audit ID</td>"
+ "<td width='15%' style='text-align:center'>Overdue/Delayed</td>"
+ "<td width='15%' style='text-align:center'>Due in next 30 days</td>"
+ "<td width='15%' style='text-align:center'>Due beyond 30 days</td>"
+ "<td width='10%' style='text-align:center'>Total</td>"
+ "<td width='15%' style='text-align:center'>Total</td>"
+ "</tr>");
if (dtAuditorOwner != null && dtAuditorOwner.Rows.Count > 0)
{
foreach (DataRow _row in dtAuditorOwner.Rows)
{
if (Convert.ToString(_row["RTotal"]) != "0")
{
strbuilder.Append("<tr><td width='15%' style='text-align:center'>");
strbuilder.Append(_row["AuditID"]);
strbuilder.Append("</td>");
strbuilder.Append("<td width='15%' style='text-align:center'>");
strbuilder.Append(_row["AuditName"].ToString());
strbuilder.Append("</td>");
strbuilder.Append("<td width='15%' style='text-align:center'>");
strbuilder.Append(_row["ODRecommendation"].ToString());
strbuilder.Append("</td>");
strbuilder.Append("<td width='15%' style='text-align:center'>");
strbuilder.Append(_row["Dueinnext30days"].ToString());
strbuilder.Append("</td>");
strbuilder.Append("<td width='15%' style='text-align:center'>");
strbuilder.Append(_row["Duebeyond30days"].ToString());
strbuilder.Append("</td>");
strbuilder.Append("<td width='10%' style='text-align:center'>");
strbuilder.Append(_row["RTotal"].ToString());
strbuilder.Append("<td width='15%' style='text-align:center'>");
strbuilder.Append(_row["RecPendingApproval"]);
strbuilder.Append("</td>");
strbuilder.Append("</tr>");
}
}
}
strbuilder.Append("</table></td></tr>");
strbuilder.Append("<tr>Please click on the " + " <a href=" + siteurl + "/_layouts/EY.IAA.Login/LoginPage.aspx>link</a>" + " to review & take action on the same</tr>"
+ "<tr>Regards<br/>Admin</tr>"
+ "</table>");
objIAAEmail.MailBody = strbuilder.ToString();
MailSend(objIAAEmail, oSpWeb);
}
}
}
public bool MailSend(IAAEmail objIAAEmail, SPWeb oWeb)
{
bool result = false;
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
if (!string.IsNullOrEmpty(Convert.ToString(objIAAEmail)))
{
MailMessage message = new MailMessage(MailFrom, objIAAEmail.ToMailAddress);
message.Subject = Convert.ToString(objIAAEmail.MailSubject);
message.Body = Convert.ToString(objIAAEmail.MailBody);
message.IsBodyHtml = true;
NetworkCredential nc = new NetworkCredential(MailUserName, MailPassword);
SmtpClient smtpClient = new SmtpClient(smtpClientHost);
smtpClient.Port = SMTPPort;
smtpClient.Credentials = nc;
smtpClient.Send(message);
message.Dispose();
result = true;
}
});
return result;
}
catch (Exception ex)
{
throw ex;
}
}
No comments:
Post a Comment