August 30,2005 16:47

如何從 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


  • phanix 發表於樂多回應(7)引用(0)電腦網路編輯本文
    樂多分類:網路/3C │昨日人次:0 │累計人次:1990
    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

    請問以下的 schemas.microsoft.com 語法不用改自己的是嗎?! 謝謝!

    http://schemas.microsoft.com/cdo/configuration/sendusing
    | 檢舉 | Posted by Grace at May 4,2009 13:26
    沒想到這文章還有人在看.. @@"
    那個 http://schemas.microsoft.com/cdo/configuration/sendusing 照著用就可以了,不需要改。詳細的資料可以去查 MSDN 說明文件。

    另,本 blog 搬家搬很久了 @@"
    | 檢舉 | Posted by Phanix at May 4,2009 14:31

    讚!很好用!我去申請免費空間,它只能使用外部的smtp,找了好久終於找到好用的程式。謝謝
    | 檢舉 | Posted by rainpo17 at April 17,2010 10:18

    謝謝你大大,謝謝您不藏私的分享

    幫了非常大的忙
    | 檢舉 | Posted by sean at August 25,2011 11:04