Skip to content

Instantly share code, notes, and snippets.

@kuro1981
Last active June 7, 2019 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuro1981/f194315c9cfa693113ebebf0029d6724 to your computer and use it in GitHub Desktop.
Save kuro1981/f194315c9cfa693113ebebf0029d6724 to your computer and use it in GitHub Desktop.
Excel email on CDO.Message
sub mailtest()
Call MailSend("test", "2222", True)
End Sub
Sub MailSend(Subj As String, Msg As String, IsSSL As Boolean)
'///////////////////////////////////////
'//SMTP Configuration Settings
Dim FileName As String
Dim iMsg As Object
Dim iConf As Object
Dim Flds As Variant
Dim Attach As String
'Attach = "C:\Users\Glen\Documents\Passwords.xlsx"
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1
Set Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
= "smtp.aaaa.bbb.jp"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "user"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "pass"
'Specifies the method used to send messages:
'(1) Local SMTP Pickup Service (2) Use SMTP Over Network (3) Use Exchange Server
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'smtpusessl
'Indicates whether Secure Sockets Layer (SSL) should be used when
'sending messages using the SMTP protocol over the network or not.
'SSL/STARTTLS: Boolean
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = IsSSL
'smtpconnectiontimeout
'Maximum Time in Seconds CDO will try to Establish Connection
'.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = <whatever>
.Update
End With
If Msg = "" Then
Msg = "Test message area" & vbCrLf & vbCrLf
End If
'Create Mail Item ans send it
With iMsg
Set .Configuration = iConf
.To = "from@aaa.bbb.jp"
'.To = EmailAddr
.From = """kero"" <aaa@aaa.bbb.jp>"
'.CC = "" ';"ccc@aaa.bbb.jp"
'.CC = "bbb@aaa.bbb.jp;"
.BCC = ""
.Subject = Subj
.TextBody = Msg
'.AddAttachment Attach
.Send
End With
'//////////////////////////////////////
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment