[c#]代码库
public static void SendMailLocalhost(string MailType,XmlOpseae Opseae)
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
//首先获取发件人 发件公司 发件邮箱(委托方) // 收件人 收件公司 收件邮箱(承运方)
var strSql = new StringBuilder();
strSql.Append(" select case AUDITOR WHEN '' then ");
strSql.Append(" (select email from userinfo where userid in (select userid from login where companyID=FORWARDER) and departmentID='CompanyMaster') ");
strSql.Append(" else (select email from userinfo where userid=AUDITOR) end ReceiverEmail ");
strSql.Append(" ,case AUDITOR WHEN '' then ");
strSql.Append(" (select username from userinfo where userid in (select userid from login where companyID=FORWARDER) and departmentID='CompanyMaster') ");
strSql.Append(" else (select username from userinfo where userid=AUDITOR) end Receivername ");
strSql.Append(" ,u.username sendername,u.email senderEmail ");
strSql.Append(" ,(select fullname from company where companyid=bcs.forwarder) receiverCompany ");
strSql.Append(" ,(select fullname from company where companyid=bcs.companyid) sendercompany ");
strSql.Append(" ,(select Mobile from userinfo where userid=bcs.inputby) senderMobile ");
strSql.Append(" ,(select Mobile from userinfo where userid=bcs.Auditor) receiverMobile ");
strSql.Append(" ,bcs.* ");
strSql.Append(" from BookingCargoSpace bcs ");
strSql.Append(" left join userinfo U on u.userid = bcs.inputby ");
strSql.Append(" where bsno='" + Opseae.BSNO + "' ");
DataSet ds = new DataSet();
Database db = DatabaseFactory.CreateDatabase();
var SenderName = "";
var SenderEmail = "";
var SenderCompany = "";
var SenderMobile = "";
var ReceiverName = "";
var ReceiverEmail = "";
var ReceiverCompany = "";
var ReceiverMobile = "";
var EmailText = new StringBuilder();
var EmailTitle = new StringBuilder();
try
{
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()) )
{
while (reader.Read())
{
SenderName = Convert.ToString(reader["SenderName"]);
SenderEmail = Convert.ToString(reader["SenderEmail"]);
SenderCompany = Convert.ToString(reader["SenderCompany"]);
SenderMobile = Convert.ToString(reader["SenderMobile"]);
ReceiverName = Convert.ToString(reader["ReceiverName"]);
ReceiverEmail = Convert.ToString(reader["ReceiverEmail"]);
ReceiverCompany = Convert.ToString(reader["ReceiverCompany"]);
ReceiverMobile = Convert.ToString(reader["ReceiverMobile"]);
EmailTitle.Clear();
EmailTitle.Append("");
}
reader.Close();
}
}
catch (Exception)
{
}
finally
{
}
if (MailType == "拒绝订舱" || MailType == "待定" || MailType == "拒绝提单确认")
{
msg.To.Add( SenderEmail);
msg.From = new MailAddress(ReceiverEmail, ReceiverName, System.Text.Encoding.UTF8);
}
else {
msg.To.Add(ReceiverEmail);
msg.From = new MailAddress(SenderEmail, SenderName, System.Text.Encoding.UTF8);
}
/* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/
var Subject = "";
var Body = new StringBuilder();
if (MailType == "订舱") {
Subject = " 订舱:From "+SenderCompany;
if (Opseae.ETD!="")
Subject = Subject+" 船期"+Opseae.ETD;
if (Opseae.CNTR != "")
Subject = Subject + " 箱型箱量" + Opseae.CNTR;
if (Opseae.DESTINATION != "")
Subject = Subject + " 目的地" + Opseae.DESTINATION;
//Body.Append(Subject);
Body.Append("<html> <Body>订舱公司:" + SenderCompany);
Body.Append("<br />订舱人:" + SenderName + " 电话:" + SenderMobile + " 邮箱:" + SenderEmail);
if (Opseae.CNTR != "")
Body.Append("<br />箱型箱量:" + Opseae.CNTR);
if (Opseae.ETD != "")
Body.Append("<br />船期:" + Opseae.ETD);
if (Opseae.CNTR != "")
Body.Append("<br />目的地:" + Opseae.DESTINATION);
if (Opseae.BOOKINGDESCRIPTION != "")
Body.Append("<br />订舱说明:" + Opseae.BOOKINGDESCRIPTION);
}
if (MailType == "退舱")
{
Subject = " 退舱申请:From " + SenderCompany;
if (Opseae.ETD != "")
Subject = Subject + " 船期" + Opseae.ETD;
if (Opseae.CNTR != "")
Subject = Subject + " 箱型箱量" + Opseae.CNTR;
if (Opseae.DESTINATION != "")
Subject = Subject + " 目的地" + Opseae.DESTINATION;
Body.Append("<html> <Body>");
Body.Append("<br />您好,我公司希望撤回通过ShippingBox所订的此条业务,原因如下:<br />" + REHH(Opseae.PendingReason));
Body.Append("<br />订舱公司:" + SenderCompany);
Body.Append("<br />订舱人:" + SenderName + " 电话:" + SenderMobile + " 邮箱:" + SenderEmail);
if (Opseae.CNTR != "")
Body.Append("<br />箱型箱量:" + Opseae.CNTR);
if (Opseae.ETD != "")
Body.Append("<br />船期:" + Opseae.ETD);
if (Opseae.CNTR != "")
Body.Append("<br />目的地:" + Opseae.DESTINATION);
if (Opseae.BOOKINGDESCRIPTION != "")
Body.Append("<br />订舱说明:" + Opseae.BOOKINGDESCRIPTION);
}
if (MailType == "拒绝订舱")
{
Subject = " 拒绝订舱提醒:From " + ReceiverCompany;
if (Opseae.ETD != "")
Subject = Subject + " 船期" + Opseae.ETD;
if (Opseae.CNTR != "")
Subject = Subject + " 箱型箱量" + Opseae.CNTR;
if (Opseae.DESTINATION != "")
Subject = Subject + " 目的地" + Opseae.DESTINATION;
Body.Append("<html> <Body>");
Body.Append("<br />您好,您通过ShippingBox所订业务被拒绝,理由如下:<br />" + REHH(Opseae.PendingReason));
Body.Append("<br />订舱代理公司:" + ReceiverCompany);
Body.Append("<br />操作人:" + ReceiverName + " 电话:" + ReceiverMobile + " 邮箱:" + ReceiverEmail);
if (Opseae.CNTR != "")
Body.Append("<br />箱型箱量:" + Opseae.CNTR);
if (Opseae.ETD != "")
Body.Append("<br />船期:" + Opseae.ETD);
if (Opseae.CNTR != "")
Body.Append("<br />目的地:" + Opseae.DESTINATION);
if (Opseae.BOOKINGDESCRIPTION != "")
Body.Append("<br />订舱说明:" + Opseae.BOOKINGDESCRIPTION);
}
if (MailType == "待定")
{
Subject = " 订舱被待定:From " + SenderCompany;
if (Opseae.ETD != "")
Subject = Subject + " 船期" + Opseae.ETD;
if (Opseae.CNTR != "")
Subject = Subject + " 箱型箱量" + Opseae.CNTR;
if (Opseae.DESTINATION != "")
Subject = Subject + " 目的地" + Opseae.DESTINATION;
//Body.Append(Subject);
Body.Append("<html> <Body>接收订舱公司:" + SenderCompany);
Body.Append("<br />操作人:" + SenderName + " 电话:" + SenderMobile + " 邮箱:" + SenderEmail);
if (Opseae.CNTR != "")
Body.Append("<br />箱型箱量:" + Opseae.CNTR);
if (Opseae.ETD != "")
Body.Append("<br />船期:" + Opseae.ETD);
if (Opseae.CNTR != "")
Body.Append("<br />目的地:" + Opseae.DESTINATION);
if (Opseae.BOOKINGDESCRIPTION != "")
Body.Append("<br />订舱说明:" + Opseae.BOOKINGDESCRIPTION);
if (Opseae.PendingReason != "")
Body.Append("<br />待定理由:" + REHH(Opseae.PendingReason));
}
if (MailType == "拒绝提单确认")
{
Subject = " 拒绝提单确认:From " + ReceiverCompany;
if (Opseae.ETD != "")
Subject = Subject + " 船期" + Opseae.ETD;
if (Opseae.CNTR != "")
Subject = Subject + " 箱型箱量" + Opseae.CNTR;
if (Opseae.DESTINATION != "")
Subject = Subject + " 目的地" + Opseae.DESTINATION;
Body.Append("<html> <Body>");
Body.Append("<br />您好,您通过ShippingBox所提交提单确认被拒绝,理由如下:<br />" + REHH(Opseae.PendingReason));
Body.Append("<br />订舱代理公司:" + ReceiverCompany);
Body.Append("<br />操作人:" + ReceiverName + " 电话:" + ReceiverMobile + " 邮箱:" + ReceiverEmail);
if (Opseae.CNTR != "")
Body.Append("<br />箱型箱量:" + Opseae.CNTR);
if (Opseae.ETD != "")
Body.Append("<br />船期:" + Opseae.ETD);
if (Opseae.CNTR != "")
Body.Append("<br />目的地:" + Opseae.DESTINATION);
if (Opseae.BOOKINGDESCRIPTION != "")
Body.Append("<br />订舱说明:" + Opseae.BOOKINGDESCRIPTION);
}
Body = SetBottom(Body, Opseae.BSNO);
msg.Subject = Subject;//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
msg.Body = Body.ToString();//邮件内容
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = true;//是否是HTML邮件
msg.Priority = MailPriority.High;//邮件优先级
var content = "";
AlternateView htmlBody = AlternateView.CreateAlternateViewFromString(content, null, "text/html");
/*
LinkedResource lrImage = new LinkedResource(@"D:\DSWebservice\a.jpg", "image/gif");
lrImage.ContentId = "Email001";
htmlBody.LinkedResources.Add(lrImage);
msg.AlternateViews.Add(htmlBody);*/
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("admin@dongshengsoft.com", "ds!@#)(*");
//在71info.com注册的邮箱和密码
client.Host = "smtpcom.263xmail.com";
object userState = msg;
var Result = "";
try
{
//client.SendAsync(msg, userState);
//简单一点儿可以
client.Send(msg);
//MessageBox.Show("发送成功");
}
catch (System.Net.Mail.SmtpException ex)
{
Result = ex.Message;
}
}
public static void SendMSGMail ( XmlMSGInfo Mail )
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
//首先获取发件人 发件公司 发件邮箱(委托方) // 收件人 收件公司 收件邮箱(承运方)
var strSql = new StringBuilder();
strSql.Append(" select M.*,S.userName S_userName,S.mobile S_mobile,S.email S_email,S.fullName S_Company ");
strSql.Append(" ,r.userName R_userName,r.mobile R_mobile,r.email R_email,R.fullName R_Company from BookingMSG m ");
strSql.Append(" left join vw_user S on s.userID=m.SENDERID ");
strSql.Append(" left join vw_user R on R.userID=m.RECEIVERID ");
strSql.Append(" where BSNO='" + Mail.BSNO + "' and MSGDate='" + Mail.MSGDate + "' ");
DataSet ds = new DataSet();
Database db = DatabaseFactory.CreateDatabase();
var SenderName = "";
var SenderEmail = "";
var SenderCompany = "";
var SenderMobile = "";
var ReceiverName = "";
var ReceiverEmail = "";
var ReceiverCompany = "";
var ReceiverMobile = "";
var BSNO = "";
var EmailText = new StringBuilder();
var EmailTitle = new StringBuilder();
try
{
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
SenderName = Convert.ToString(reader["S_userName"]);
SenderEmail = Convert.ToString(reader["S_email"]);
SenderCompany = Convert.ToString(reader["S_Company"]);
SenderMobile = Convert.ToString(reader["S_mobile"]);
ReceiverName = Convert.ToString(reader["R_userName"]);
ReceiverEmail = Convert.ToString(reader["R_email"]);
ReceiverCompany = Convert.ToString(reader["R_Company"]);
ReceiverMobile = Convert.ToString(reader["R_mobile"]);
BSNO = Convert.ToString(reader["BSNO"]);
EmailTitle.Clear();
EmailTitle.Append("");
}
reader.Close();
}
}
catch (Exception)
{
}
finally
{
}
msg.To.Add(ReceiverEmail);
msg.From = new MailAddress(SenderEmail, SenderName, System.Text.Encoding.UTF8);
var Subject = "";
var Body = new StringBuilder();
var Opseae = GetBookingCargoSpace(BSNO);
Subject = " 沟通消息: " + SenderCompany;
if (Opseae.VESSEL != "")
Subject = Subject + "--" + Opseae.VESSEL;
if (Opseae.VOYNO != "")
Subject = Subject + "--" + Opseae.VOYNO;
if (Opseae.MBLNO != "")
Subject = Subject + "--" + Opseae.MBLNO;
if (Opseae.ETD != "")
Subject = Subject + "--" + Opseae.ETD;
if (Opseae.CNTR != "")
Subject = Subject + "--" + Opseae.CNTR;
if (Opseae.DESTINATION != "")
Subject = Subject + "--" + Opseae.DESTINATION;
//Body.Append(Subject);
Body.Append("<html> <Body>关于 ");
if (Opseae.VESSEL != "")
Body.Append("--" + Opseae.VESSEL);
if (Opseae.VOYNO != "")
Body.Append( "--" + Opseae.VOYNO);
if (Opseae.MBLNO != "")
Body.Append( "--" + Opseae.MBLNO);
if (Opseae.ETD != "")
Body.Append( "--" + Opseae.ETD);
if (Opseae.CNTR != "")
Body.Append( "--" + Opseae.CNTR);
if (Opseae.DESTINATION != "")
Body.Append( "--" + Opseae.DESTINATION);
Body.Append(":<br />" + REHH( Mail.FieldValue));
Body.Append("<br /><br />联系人:" + SenderName + " 电话:" + SenderMobile + " 邮箱:" + SenderEmail);
Body = SetBottom(Body, Opseae.BSNO);
msg.Subject = Subject;//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
msg.Body = Body.ToString();//邮件内容
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = true;//是否是HTML邮件
msg.Priority = MailPriority.High;//邮件优先级
var content = "";
AlternateView htmlBody = AlternateView.CreateAlternateViewFromString(content, null, "text/html");
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("admin@dongshengsoft.com", "ds!@#)(*");
//在71info.com注册的邮箱和密码
client.Host = "smtpcom.263xmail.com";
object userState = msg;
var Result = "";
try
{
//client.SendAsync(msg, userState);
//简单一点儿可以
client.Send(msg);
//MessageBox.Show("发送成功");
}
catch (System.Net.Mail.SmtpException ex)
{
Result = ex.Message;
}
}
by: 发表于:2017-12-18 09:39:32 顶(0) | 踩(0) 回复
??
回复评论