用HTML格式发送邮件

用HTML格式发送邮件 
文章出处:联动天下 作者:联动天下 发布时间:2005-12-21 
你可以通过SMTP服务或者MS Exchange发送HTML格式的邮件,但是,你需要注意的是,并不是所有的clients都可以正常显示。在通常的情况下,CDONTS发送邮件是使用plain-text格式。在使用HTML方式的时候我们可以进行更多的设置,例如不同的字体,颜色,插入图片等等。下面是一个例子
<%
Dim objMail
Set objMail = Server.CreateObject("CDONTS.NewMail")

'//these are all the images that are in this message.
'//you must include them like this.
'//please note that you DO NOT have TO write the
'//entire file path in the <IMG> tag in the body after this.
'//make sure you see the image name after the path separated by a comma

objMail.AttachURL "D:\images\myImage.gif", "myImage.gif" 
objMail.AttachURL "D:\images\myImage2.gif", "myImage2.gif"


HTML = HTML & "<HTML>"
HTML = HTML & "<HEAD>"
HTML = HTML & "<TITLE>Send Mail with HTML</TITLE>"
HTML = HTML & "</HEAD>"
HTML = HTML & "<BODY bgcolor=""lightyellow"">"
HTML = HTML & "<TABLE cellpadding=""4"">"
HTML = HTML & "<TR><TH><FONT color=""darkblue"" SIZE=""4"">"
HTML = HTML & now() & " - "
HTML = HTML & "These are all great ASP Sites</FONT></TH></TR>" 
HTML = HTML & "<TR><TD>"
HTML = HTML & "<A HREF=""http://www.4guysfromrolla.com"">"
HTML = HTML & "<IMG SRC=""myImage.gif""></A><BR><BR>"
HTML = HTML & "<A HREF=""http://www.4guysfromrolla.com"">"
HTML = HTML & "<IMG SRC=""myImage2.gif""></A><BR><BR>"
HTML = HTML & "</FONT></TD></TR></TABLE><BR><BR>"
HTML = HTML & "</BODY>"
HTML = HTML & "</HTML>"

objMail.From = "rob@tconsult.com"
objMail.Subject = "Your daily HTML Mail"

'you need TO add these lines FOR the mail
'to be sent in HTML format
objMail.BodyFormat = 0 
objMail.MailFormat = 0

objMail.To = "you@yourhouse.com
objMail.Body = HTML
objMail.Send

Response.write("Mail was Sent")
set objMail = nothing
%>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个示例代码,展示如何使用Python发送HTML格式的电子邮件: ```python import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.mime.image import MIMEImage # 邮件发送者和接收者的信息 sender = 'sender@example.com' receiver = 'receiver@example.com' # 邮件主题 subject = 'HTML格式邮件' # 邮件正文内容 html = """ <html> <head></head> <body> <p>这是一封HTML格式的邮件!</p> <p>以下是一张图片:</p> <img src="cid:image1"> </body> </html> """ # 创建包含HTML内容的MIMEText对象 msg = MIMEMultipart('related') msg['Subject'] = subject msg['From'] = sender msg['To'] = receiver html_part = MIMEText(html, 'html') msg.attach(html_part) # 添加图片 with open('image.jpg', 'rb') as f: img = MIMEImage(f.read()) img.add_header('Content-ID', '<image1>') msg.attach(img) # 发送邮件 smtp_server = 'smtp.example.com' smtp_port = 587 smtp_username = 'username' smtp_password = 'password' server = smtplib.SMTP(smtp_server, smtp_port) server.ehlo() server.starttls() server.login(smtp_username, smtp_password) server.sendmail(sender, receiver, msg.as_string()) server.quit() ``` 在上述代码中,我们创建了一个 `MIMEMultipart` 对象,并使用 `MIMEText` 类将HTML内容添加为邮件正文。同时,我们还添加了一张图片,并使用 `MIMEImage` 类将其作为附件添加到邮件中,并在HTML中通过 `Content-ID` 引用该图片。最后,我们使用SMTP协议发送邮件

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值