//发送邮件
MailMessage msgMail = new MailMessage();
//目标地址
msgMail.To =strToMail;
//源地址
msgMail.From=strFromMail;
msgMail.Cc="";
//主题
msgMail.Subject="请假审批没有同意";
//内容
System.Net.IPHostEntry hostInfo = System.Net.Dns.GetHostByAddress(Request.UserHostAddress);
msgMail.Body = "您好!\n"
+ "" + strName + ""
+ "您的请假单审批没有通过,请查收。\n"
//尝试发送邮件
try
{
//邮件服务器:地址在web.config配置文件中
SmtpMail.SmtpServer = System.Configuration.ConfigurationSettings.AppSettings.Get(1); //发送邮件
SmtpMail.Send(msgMail);
}
catch (System.Exception ex)
{
//无法发送时提示
ANSServices.common.clsCommonProc.MsgBox(this,clsTools.GetMsgContent("GetPassword",clsMessages.GETPASSWORD_MSG_1002));
return;
}问题是msgMail.Body中如果没有换行则发送成功,如果有换行则发送不成功。试过很多种解码和编码的方式。。貌似都不行。
MailMessage msgMail = new MailMessage();
//目标地址
msgMail.To =strToMail;
//源地址
msgMail.From=strFromMail;
msgMail.Cc="";
//主题
msgMail.Subject="请假审批没有同意";
//内容
System.Net.IPHostEntry hostInfo = System.Net.Dns.GetHostByAddress(Request.UserHostAddress);
msgMail.Body = "您好!\n"
+ "" + strName + ""
+ "您的请假单审批没有通过,请查收。\n"
//尝试发送邮件
try
{
//邮件服务器:地址在web.config配置文件中
SmtpMail.SmtpServer = System.Configuration.ConfigurationSettings.AppSettings.Get(1); //发送邮件
SmtpMail.Send(msgMail);
}
catch (System.Exception ex)
{
//无法发送时提示
ANSServices.common.clsCommonProc.MsgBox(this,clsTools.GetMsgContent("GetPassword",clsMessages.GETPASSWORD_MSG_1002));
return;
}问题是msgMail.Body中如果没有换行则发送成功,如果有换行则发送不成功。试过很多种解码和编码的方式。。貌似都不行。
还加上这一句msgMail.BodyEncoding = System.Text.Encoding.UTF8;
objMailMessage.BodyEncoding = System.Text.Encoding.UTF8;
objMailMessage.From = "[email protected]";//源邮件地址
objMailMessage.To = txtEmail.Text.Trim();//目的邮件地址,也就是发给我哈
objMailMessage.Subject ="成功注册欢迎信件";//发送邮件的标题
objMailMessage.Body = "" + body+ " ";//发送邮件的内容
//objMailMessage.Attachments.Add(mac);//将附件附加到邮件消息对象中 //接着利用sina的SMTP来发送邮件,需要使用Microsoft .NET Framework SDK v1.1和它以上的版本 //基本权限
objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//用户名
objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "service");
//密码
objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "ectrader888"); //如果没有上述三行代码,则出现如下错误提示:服务器拒绝了一个或多个收件人地址。服务器响应为: 554 : Client host rejected: Access denied //SMTP地址
SmtpMail.SmtpServer = "mail.ectrader.com.hk"; //开始发送邮件
try
{
SmtpMail.Send(objMailMessage);
}
catch(Exception ex)
{
PComm.Comm.Show(this.Page, "注册成功,但邮件发送出错,请手动打开主页");
}试试我这个
//文本种类
msgMail.BodyFormat = Web.Mail.MailFormat.Text;
//文本编码
msgMail.BodyEncoding = System.Text.Encoding.UTF8;