ASP Jmail 发送带附件的HTML邮件
asp通过jmail组件发送邮件,附加福建或者内嵌附件
需要注意到一点是:JMail.ContentType = “text/html”要注释掉
(为什么要发内嵌的附件图片?因为如果是img src=网上的地址,在outlook等客户端内则显示是难看的“X”,需要手动下载图片)
<% Set JMail = Server.CreateObject("JMail.Message") '是否将信头编码成iso-8859-1字符集. 缺省是True JMail.ISOEncodeHeaders = True '如果JMail.silent设置为true,ErrorCode包含的是错误代码 JMail.Silent = True '设置标题和内容编码,如果标题有中文,必须设定编码为gb2312 JMail.Charset = "gb2312" 'JMail.ContentType = "text/html" '如果发内嵌附件一定要注释掉这行,重要! JMail.From = "web@qq.com" ' 发送者地址 JMail.FromName = "Skyhe System" ' 发送者姓名 JMail.MailServerUserName = "web" ' 身份验证的用户名 JMail.MailServerPassword = "123456" ' 身份验证的密码 '加入新的收件人 JMail.AddRecipient "web2@qq.com", "Mr.Example" 'JMail.AddRecipientBCC Email '密件收件人的地址 'JMail.AddRecipientCC Email '邮件抄送者的地址 JMail.Subject = "图片测试!!!" JMail.Body = "A nice picture if you can read HTML-mail." '增加一个普通附件 JMail.AddAttachment(Server.MapPath("images/email.gif")) '增加一个嵌入式附件 ' The return value of AddAttachment is used as a ' reference to the image in the HTMLBody. 'contentId = JMail.AddAttachment(Server.MapPath("images/email.gif")) Dim contentId contentId = JMail.AddAttachment("E:\images\email.gif") '只有HTML格式支持嵌入图片附件,我们采用HTML格式的邮件内容 ' As only HTML formatted emails can contain inline images ' we use HTMLBody and appendHTML JMail.HTMLBody = "<html><body><font color=""red"">Hi, here is a nice picture:</font><br>" JMail.appendHTML "<img src=""cid:" & contentId & """>" JMail.appendHTML "<br><br> good one huh?</body></html>" '如果对方信箱不支持HTML格式邮件,我们仍需要给他一个友善的提示 ' But as not all mailreaders are capable of showing HTML emails ' we will also add a standard text body JMail.Body = "Too bad you can't read HTML-mail." JMail.appendText " There would have been a nice picture for you" JMail.Send( "smtp.qq.com" ) '这里是QQ邮箱的写法 JMail.Close() Set JMail = Nothing %>
set msg = Server.CreateOBject("JMail.Message") '设置标题和内容编码,如果标题有中文,必须设定编码为gb2312 msg.Charset = "gb2312" msg.ContentType = "text/html" '如果发内嵌附件一定要注释掉这行,重要! msg.From = "elgin8848@163.com" msg.FromName = "shunzemachine.com" msg.MailServerUserName="elgin8848@163.com"'(填电子邮件的用户名) msg.MailServerPassWord="***8848"'(填电子邮件的密码) msg.AddRecipient "######@qq.com"'(填你想发送的电子邮箱) msg.Subject = trim(request("title")) msg.HTMLBody ="<html><body>"+ trim(request("content"))+"</body></html>" 'msg.appendText "Here’s some text." 'msg.appendText "And here’ s some more" msg.Send( "smtp.163.com" )'(如果用的不是163,请换成其它的SMTP服务器) response.write "ok"