csharp 再次发送电子邮件模板 - 拉动公司设置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 再次发送电子邮件模板 - 拉动公司设置相关的知识,希望对你有一定的参考价值。

// Email Notification
//
// 08/01/17 HK: Initial Implementation, since this is considered a temporary, lets keep it simple
//

// Initialize Actions
Func<string, string> GetCompanyAddressAction = (CompanyID) => {

	var Company_Row =
		(from sc in Db.SysCompany.With(LockHint.NoLock)
		where sc.Company == CompanyID
		select new { sc.EmailFromAddr, sc.EmailFromLabel }).FirstOrDefault();

	if (Company_Row != null) {
		return string.Format(@"""{0}"" <{1}>", Company_Row.EmailFromLabel.Trim(), Company_Row.EmailFromAddr.Trim());
	}

	return string.Empty;
};

Func<string, string> GetCostPerCode = (CostPerCode) => {

	switch (CostPerCode)
	{
		case "E":
			return @"/ 1";

		case "C":

			return @"/ 100";

		case "M":
			return @"/ 1000";
	}

	return string.Empty;
};


// Initialize Variables
string EmailTO = "haso.keric@xyz.com";
string EmailCC = "";
string EmailBCC = "";
string EmailSubject = "";
string EmailBody = "";

// Get POHeader
var ttPOHeader_Row = ttPOHeader.FirstOrDefault();

if (ttPOHeader_Row != null)
{
	// Get Vendor ID and Name
	var Vendor_Row =
		(from v in Db.Vendor.With(LockHint.NoLock)
		where
			v.Company == ttPOHeader_Row.Company &&
			v.VendorNum == ttPOHeader_Row.VendorNum
		select new { v.Name, v.VendorID }
		).FirstOrDefault();

	// Set Subject
	EmailSubject = "[ Alert ] PO #: " + ttPOHeader_Row.PONum + " was issued from Company " + ttPOHeader_Row.Company;

	// Start Email Body
	EmailBody += string.Format("Purchase Order <b>{0}</b> was issued from Company <b>{1}</b> on <b>{2}</b> to Vendor ID {3}, <b>{4}</b>, for:",
								ttPOHeader_Row.PONum, ttPOHeader_Row.Company, ttPOHeader_Row.OrderDate.Value.ToShortDateString(), Vendor_Row.VendorID, Vendor_Row.Name );

  	EmailBody += "<BR><BR>";


	EmailBody +=
		@"<table width='100%' align='center' border='1' cellspacing='1' cellpadding='1' style='font-family: Arial; font-size: 10pt;' bordercolor='#CCCCCC'>"
		+ "<tr>"
		+ "<th>Line</th>"
		+ "<th>Part</th>"
		+ "<th>Our Qty</th>"
		+ "<th>Vend Qty</th>"
		+ "<th>Unit Cost</th>"
		+ "</tr>";


	// Get PO Lines
	var ttPODtl_Rows =
		from pod in Db.PODetail.With(LockHint.NoLock)
		where
			pod.Company == ttPOHeader_Row.Company &&
			pod.PONUM == ttPOHeader_Row.PONum
		select new { pod.POLine, pod.PartNum, pod.XOrderQty, pod.OrderQty, pod.IUM, pod.PUM, pod.LineDesc, pod.DocUnitCost, pod.CostPerCode };

	foreach (var ttPODtl_Row in ttPODtl_Rows)
	{
		EmailBody +=
		  "<tr>"
		+ @"<td align='center'>" + ttPODtl_Row.POLine + "</td>"
		+ @"<td align='center'><b>" + ttPODtl_Row.PartNum + @"</b><br><span style='font-size: 8pt'>" + ttPODtl_Row.LineDesc + "</span></td>"
		+ @"<td align='center'>" + Math.Round(ttPODtl_Row.XOrderQty, 2) + " " + ttPODtl_Row.IUM + "</td>"
		+ @"<td align='center'>" + Math.Round(ttPODtl_Row.OrderQty, 2) + " " + ttPODtl_Row.PUM + "</td>"
		+ @"<td align='center'>" + Math.Round(ttPODtl_Row.DocUnitCost, 2) + " " + GetCostPerCode(ttPODtl_Row.CostPerCode) + "</td>"
		+ "</tr>";
	}


	EmailBody += "</table>";

	// Send Email
	var mailer = this.GetMailer(async:true);
	var message = new Ice.Mail.SmtpMail();
	message.SetFrom( GetCompanyAddressAction(ttPOHeader_Row.Company) );
	message.SetTo(EmailTO);
	message.SetCC(EmailCC);
	message.SetBcc(EmailBCC);
	message.SetSubject(EmailSubject);
	message.SetBody(EmailBody);
	message.IsBodyHtml = true;
	mailer.Send(message);
}

以上是关于csharp 再次发送电子邮件模板 - 拉动公司设置的主要内容,如果未能解决你的问题,请参考以下文章

csharp C#中的电子邮件发送

csharp 致电SMO并发送电子邮件

csharp 发送电子邮件

csharp 发送电子邮件

csharp 发送电子邮件

UIRefreshControl 再次拉动时出现多次