Skip to content

Instantly share code, notes, and snippets.

@honda0510
Created March 9, 2012 16:33
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 honda0510/2007377 to your computer and use it in GitHub Desktop.
Save honda0510/2007377 to your computer and use it in GitHub Desktop.
CDOでHTMLメール送信
Option Explicit
Sub test()
Const cdoSendUsingPort = 2
Dim conf
Dim msg
Dim html_path
Dim html
Set conf = CreateObject("CDO.Configuration")
With conf.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTP SERVER"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "EMAIL"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "PASSWORD"
.Update
End With
html_path = "body.html"
html = ReadAllTextFile(html_path)
Set msg = CreateObject("CDO.Message")
With msg
Set .Configuration = conf
.To = "EMAL"
.From = "EMAL"
.Subject = "SUBJECT"
.HTMLBody = html
.Send
End With
Set msg = Nothing
Set conf = Nothing
MsgBox "Mail Sent!"
End Sub
Function ReadAllTextFile(path)
Const ForReading = 1
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(path, ForReading)
ReadAllTextFile = f.ReadAll
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment