问题描述
希望能有细一点的注释.谢谢了
解决方案
解决方案二:
SmtpClientmailServer=newSmtpClient();mailServer.Host=Host;mailServer.Port=Port;mailServer.EnableSsl=EnableSsl;mailServer.UseDefaultCredentials=false;mailServer.Credentials=newNetworkCredential(UID,PWD);mailServer.Timeout=Timeout;mailServer.Timeout=Timeout;MailAddressfrom=newMailAddress(姓名<電子郵件>);MailAddressto=newMailAddress(姓名<電子郵件>;姓名<電子郵件>);MailMessagemessage=newMailMessage(from,to);message.Subject=email.Subject;message.CC.Add(姓名<電子郵件>;姓名<電子郵件>);message.Bcc.Add(姓名<電子郵件>;姓名<電子郵件>);message.Body=email.Body;foreach(stringattainattas){Attachmentattachment=newAttachment(atta);message.Attachments.Add(attachment);}message.SubjectEncoding=ConfigManager.MailEncoding;message.BodyEncoding=ConfigManager.MailEncoding;message.IsBodyHtml=true;try{mailServer.Send(_message);
解决方案三:
利用JMAIL组件吧,很不错的说然后在类中usingjamil;然后声明jmail.MessageClassMsgMail=newjmail.MessageClass();MsgMail.Logging=true;MsgMail.Silent=true;MsgMail.Charset="GB2312";//设置邮件的编码方式MsgMail.Encoding="Base64";//设置邮件的附件编码方式MsgMail.ISOEncodeHeaders=false;//是否将信头编码成iso-8859-1字符集MsgMail.From="签名,显示是谁发的";MsgMail.FromName="发送邮件的邮箱的用户名,显示是哪个邮箱发的";MsgMail.MailServerUserName="发送邮件的邮箱的用户名";MsgMail.MailServerPassWord="发送邮件的邮箱密码";//加收件人MsgMail.AddRecipient("收件人的地址,可添加多个,重复调用就可以了",null,null);//加抄送人MsgMail.AddRecipientCC("收件人的地址,可添加多个,重复调用就可以了",null,null);//加暗送人MsgMail.AddRecipientBCC("收件人的地址,可添加多个,重复调用就可以了",null);MsgMail.Subject="标题";MsgMail.Body="正文";MsgMail.AddAttachment(文件的物理路径,false,文件的类型,例如:text/plain表示txt文档);if(MsgMail.Send(Session["SMTPSvr"].ToString(),false)){Response.Redirect("./ErrorPage.aspx?error=邮件已经成功发送!");}else{Response.Redirect("./ErrorPage.aspx?error=发送失败!");}
解决方案四:
其实要看你怎么发了,System.Net.Mail和System.Web.Mail两个组件都能发邮件System.Web.Mail发送不需要服务器System.Net.Mail可以借用别人的服务器比如163,gmail什么的,具体代码网上一搜一大堆
解决方案五:
///<summary>///发送邮件,不能发送附件。///</summary>///<paramname="send">发件人地址</param>///<paramname="recieve">收件人地址</param>///<paramname="subject">邮件主题</param>///<paramname="mailbody">邮件内容允许是html</param>///<paramname="host">发件主机</param>///<paramname="pwd">密码</param>publicvoidSendMailUseGmail(stringsend,stringrecieve,stringsubject,stringmailbody,stringhost,stringpwd,Pagepage){try{System.Net.Mail.SmtpClientclient=newSystem.Net.Mail.SmtpClient();client.Host=host;client.UseDefaultCredentials=false;client.Credentials=newSystem.Net.NetworkCredential(send,pwd);client.DeliveryMethod=System.Net.Mail.SmtpDeliveryMethod.Network;System.Net.Mail.MailMessagemessage=newSystem.Net.Mail.MailMessage();message.To.Add(recieve);message.From=newSystem.Net.Mail.MailAddress(send,"派遣168网",System.Text.Encoding.UTF8);message.Subject=subject;message.Body=mailbody;message.BodyEncoding=System.Text.Encoding.UTF8;message.IsBodyHtml=true;//添加附件//System.Net.Mail.Attachmentdata=newAttachment(@"附件地址如:e:a.jpg",System.Net.Mime.MediaTypeNames.Application.Octet);//message.Attachments.Add(data);client.Send(message);System.Web.UI.ScriptManager.RegisterStartupScript(page,this.GetType(),"success","alert('邮件发送成功!');",true);}catch(Exceptionex){System.Web.UI.ScriptManager.RegisterStartupScript(page,this.GetType(),"eeror","alert('邮件发送失败!"+ex.Message+"');",true);}}