using jmail;
protected void sendMail(String sender, String senderMail, String receiver, String subject, String content)
{
jmail.MessageClass jmMessage = new jmail.MessageClass();
//設(shè)置字符集
jmMessage.Charset = "gb2312";
//發(fā)件人郵箱地址
jmMessage.From = senderMail;
//發(fā)件人姓名
jmMessage.FromName = sender;
//設(shè)置主題
jmMessage.Subject = subject;
//設(shè)置內(nèi)容
jmMessage.Body = content;
// 設(shè)置收件人郵箱
jmMessage.AddRecipient(receiver, "", "");
// 設(shè)置登陸郵箱的用戶名和密碼
jmMessage.MailServerUserName = "ss";
jmMessage.MailServerPassWord = "ss";
//設(shè)置smtp服務(wù)器地址
if (jmMessage.Send("smtp.163.com", false))
{
Response.Write("script>alert('發(fā)送成功')/script>");
}
else
Response.Write("script>alert('www.jb51.net發(fā)送失敗')/script>");
}
jmail.AddAttachment(“c:autoexec.bat”)
jmail.AddAttachment(“myImage.gif”,TRUE)
This is a multipart message in MIME format. —-NEXT_BM_AEB3968967D044DC9E208D04088C60B4 Content-Type: text/html; charset=”GB2312″ Content-Transfer-Encoding: Quoted-Printable sdfdd —-NEXT_BM_AEB3968967D044DC9E208D04088C60B4 Content-Type: application/octet-stream; name=”=?GB2312?Q?12d95384-576f-424f-bf15-f8e2397e2791=2EJPG?=” Content-Transfer-Encoding: base64 Content-Description: =?GB2312?Q?12d95384-576f-424f-bf15-f8e2397e2791=2EJPG?= Content-Disposition: inline; filename=”=?GB2312?Q?12d95384-576f-424f-bf15-f8e2397e2791=2EJPG?=” Content-ID:
2.AddURLAttachment(bstrURL, bstrAttachAs, isInline, bstrAuth) : String從指定的URL 下載文件并添加為附件。第二個參數(shù)“AttachAs”用來更改添加為附件的文件的文件名,如果Inline 屬性被設(shè)置為true,這個附件就是一個可嵌入的附件,使用ddAttachment()方法可返回content id,這在發(fā)送HTML 郵件時是非常有用的。最后一個參數(shù)為可選項,是當(dāng)服務(wù)器需要身份驗證時使用的。
測了一下,好像跟兩個方法沒什么關(guān)系。后來在網(wǎng)上有人說把Message.ContentType =”text/html”設(shè)置去掉(就是不要去設(shè)置ContentType屬性),試了一下,還真發(fā)送成功了