我不知道如何发送我的代码...所以我将其发布为答案。希望没关系。我还遇到了一个奇怪的运行时错误,这是我以前没有遇到的。除此之外它还有效。
谢谢!
丹妮尔
Option Explicit ' 为 dSavage 修改
'如果你有 GMail 账户,那么你可以试试这个例子来使用 GMail smtp 服务器
'示例将发送一条小短信
'您必须更改四行代码才能测试代码
'.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "完整的 GMail 邮件地址"
'.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "GMail密码"
'用你自己的邮件地址测试这行代码
'.To = "邮件地址接收者"
'将 YourName 更改为您要使用的 From 名称
'.From = """你的名字"" "
'如果您收到此错误:传输无法连接到服务器
'然后尝试将 SMTP 端口从 25 更改为 465
子 CDO_Mail_Example()
将 iMsg 调暗为对象
将 iConf 调暗为对象
将 strbody 变暗为字符串
将 sAddForm 调暗为字符串
将 sForm 调暗为字符串
将 Flds 变暗作为变体
Dim iSMTP_Port As Integer
Dim sFirstReviewer As String
Dim sUserName As String
Dim sGmailPassword As String
sFirstReviewer = Range("F4").Value
sUserName = Range("F6").Value & "@indicate1.com"
sGmailPassword = Range("F8").Value
iSMTP_Port = Range("F10").Value '25 at Indicate; 465 away.
sAddForm = Range("I12").Value
'sForm = Range("F4").Value
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
如果 sAddForm = "Yes" 那么
sForm = "Z:\Quality# # Document_Development# Documents_for_Review\12002-01-01 Company Handbook.doc"
别的
sForm = ""
结束如果
Debug.Print "sForm = " & sForm ' *******************************************
Debug.Print "sUserName = " & sUserName ' *******************************************
iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = sUserName
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Micro5cope"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = iSMTP_Port '25 at Indicate; 465 away.
.Update
End With
strbody = "To " & sFirstReviewer & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2" & vbNewLine & vbNewLine & _
"This is line 3" & vbNewLine & _
"This is line 4" & vbNewLine & vbNewLine & vbNewLine & _
"Z:\Quality\# # Document_Development\# Documents_for_Review\12000-00-00 Tables 9-11 Template OLD - TEST.doc" & vbNewLine & _
sForm & vbNewLine
With iMsg
Set .Configuration = iConf
.To = sFirstReviewer & "@indicate1.com"
.CC = "" 'sUserName & "; " & "johanson111@comcast.net"
.BCC = ""
.From = sUserName
.Subject = "Test Message"
.textbody = strbody
.HtmlBody = "<A HREF=""http://www.google.com/"">Google Page</A>"
.AddAttachment "Z:\Quality\# # Document_Development\12001-02-01 Document Review Form.pdf"
.AddAttachment "Z:\Quality\# # Document_Development\12001-02 Document Review Draft 9.doc"
.Send
End With
Debug.Print "CC = " & sUserName ' *******************************************
结束子