|
本帖最后由 smartsoft 于 2013-2-14 12:37 编辑
经过几天的测试和google了无数的帖子
分享方法如下(我用的英文系统):
Option Explicit
Sub Mail_CDO()
'Send an email with your GMail account and CDO Components.
Dim iMsg, iConf, Flds
Dim schema$
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
' send one copy with Google SMTP server (with autentication)
schema = "http://schemas.microsoft.com/cdo/configuration/"
Flds.Item(schema & "sendusing") = 2
Flds.Item(schema & "smtpserver") = "smtp.gmail.com"
Flds.Item(schema & "smtpserverport") = 465
Flds.Item(schema & "smtpauthenticate") = 1
Flds.Item(schema & "sendusername") = "yourname@gmail.com"
Flds.Item(schema & "sendpassword") = "your gmail password"
Flds.Item(schema & "smtpusessl") = 1
Flds.Update
With iMsg
.To = "receiver"
.Cc = "cc"
.From = "sender"
.Subject = "subject line " & Format(Now, "dd mmm")
.TextBody = "Hi ??," & vbCrLf & vbCrLf & "Please find attached:" & vbCrLf _
& "your file path" & vbCrLf & vbCrLf _
& "Kind regards," & vbCrLf & "your name"
.AddAttachment "file path"
.Organization = ""
.ReplyTo = "your email"
Set .Configuration = iConf
.Send
End With
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
End Sub
|
|