Jmail發郵件的例子_應用技巧

來源:互聯網
上載者:User
在Asp程式中用Jmail發郵件的比較多,主要是因為多數虛擬機器主機支援他,其它的支援的較少。
  下面是一個Jmail發郵件的例子代碼: 
  如果您在自己的機器上試,請下載 Jmail.dll ,下載解壓後,雙擊Setup.bat 即可完成安裝! 
複製代碼 代碼如下:

<%
On error resume next
Dim JMail, contentId
Set JMail = Server.CreateObject("JMail.Message") 
JMail.Charset = "gb2312" '''' 郵件字元集,預設為"US-ASCII"
'''' JMail.ISOEncodeHeaders = False '''' 是否進行ISO編碼,預設為True

'''' 寄件者資訊(可用變數方式賦值)
JMail.From = "xiaoz@xiaoz.com" '''' 寄件者地址
JMail.FromName = "XiaoZ.Com" '''' 寄件者姓名
JMail.Subject = "郵件主題" '''' 郵件主題

'''' 身分識別驗證
JMail.MailServerUserName = "myusername" '''' 身分識別驗證的使用者名稱
JMail.MailServerPassword = "mypassword" '''' 身分識別驗證的密碼

'''' 設定優先權,範圍從1到5,越大的優先順序越高,3為普通
JMail.Priority = 3

JMail.AddHeader "Originating-IP", Request.ServerVariables("REMOTE_ADDR")

'''' 加入一個收件者【變數email:收件者地址】可以同一語句重複加入多個
JMail.AddRecipient("xiaoz@xiaoz.com")

'''' 加入附件【變數filename:附件檔案的絕對位址,確保使用者IUSR_機器名有訪問的許可權】
'''' 【參數設定是(True)否(False)為Inline方式】
''''contentId = JMail.AddAttachment (Server.MapPath("jmail.asp"), True)

'''' 郵件主體(HTML(注意信件內連結附件的方式))
JMail.HTMLBody = "<html><head><META content=zh-cn http-equiv=Content-Language><meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312""><style type=text/css>A:link { FONT-SIZE: 9pt; TEXT-DECORATION: none; color: #000000}A:visited {FONT-SIZE: 9pt; TEXT-DECORATION: none; color: #666666}A:hover {COLOR: #ff6600; FONT-SIZE: 9pt; TEXT-DECORATION: underline}BODY {FONT-SIZE: 9pt} --></style></head><body><font color=red>郵件內文</font><br><font color=green>郵件內文</font><br><b>郵件內文</b></body></html>"

'''' 郵件主體(文本部分)
JMail.Body = "我們的郵件採用了HTML格式,但是您的郵件查看軟體可能不支援。。。郵件內文,郵件內文,郵件內文"

'''' 發送【調用格式:objJMail.Send([username:password@]SMTPServerAddress[:Port])】
JMail.Send("smtp.163.com")

'''' 關閉並清除對象
JMail.Close()
Set JMail = Nothing

if err.number<>0 then
response.write "發送發送失敗!"
else
response.write "郵件發送成功!"
end if
%>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.