Created
March 9, 2012 16:33
-
-
Save honda0510/2007377 to your computer and use it in GitHub Desktop.
CDOでHTMLメール送信
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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