August 30,2005

如何從 asp 中透過 gmail smtp 發信 / How to send mail in asp via gmail smtp

最近因為有需要從 asp 中透過 gmail smtp 發信;
不幸的是在網路上似乎只能找到 for php, jsp, .net 的 sample code,受不了乾脆來寫一個 =.=

'Create CDO.Message object instance
Set myMail = CreateObject("CDO.Message")

'============================================================
' 使用外部 SMTP
'============================================================

'設定是否使用外部 SMTP
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2     '1 代表使用 local smtp, 2 為外部 smtp


'SMTP Server domain name
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"

'Server port, gmail use ssl smtp authentication, port number is 465
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
'Authentication method, ssl or not, Username and password for the SMTP Server
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'cdoBasic 基本驗證
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"

myMail.Configuration.Fields.Update
'============================================================
' End of 使用外部 SMTP
'============================================================



myMail.Subject = strSubject
myMail.From = strEmailFrom
myMail.To = strEmailTo
myMail.TextBody = strBody
myMail.Send

set myMail=nothing


Posted by phanix at 樂多Roodo! │16:47 │回應(3)引用(0)電腦網路
樂多分類:網路/3C 共同主題:程式設計 工具:加入樂多書籤編輯本文
Ads by Roodo! 

引用URL

http://cgi.blog.roodo.com/trackback/428744
回應文章
版主你好:這個範例不錯喔..
我改成.NET C#和Delphi版..
希望你不要介意^_^
Posted by flyup2005 at August 31,2005 17:57
不好意思
請問前輩ASP的寄信可否請教您
我用此code寄,有時寄得出,有時寄不出
不知是被擋信嗎?
請問有什麼方法可以解決嗎?
感謝!!
http://192.168.1.109/ironman/article.asp?id=74
Posted by ironman at July 24,2007 12:01
不好意思
連結網址po錯
是這個
http://www.ironman.tw/ironman/article.asp?id=74
Posted by ironman at July 24,2007 12:19