Archive for 5月, 2009

WSHを利用してメールを送信する例です。
今時のメール送信はSMTP Authなどが実装されている例が多いのですが、
今回の例は、SMTP Authには対応していません。(別途、紹介します)

パラメータは以下の通り。

Send_Msg “SMTPモード”,”SMTPサーバ”,”SMTPポート”,”送信元メールアドレス”,”宛先メールアドレス”,”CC宛先”,”BCC宛先”,”件名”,”本文”


Dim STR_SmtpHost
Dim STR_SmtpPort
Dim STR_MsgFrom
Dim STR_MsgTo
Dim STR_MsgCc
Dim STR_MsgBcc
Dim STR_MsgSubject
Dim STR_MsgBody

STR_SmtpHost = "xxx"
STR_SmtpPort = "xx"
STR_MsgFrom = "xxx@xxx.com"
STR_MsgTo = "xxx@yyy.com"
STR_MsgCc = ""
STR_MsgBcc = ""
STR_MsgSubject = "aaaa"
STR_MsgBody = "bbb"

Call Send_Msg(STR_SmtpHost, STR_SmtpPort, STR_MsgFrom, STR_MsgTo, STR_MsgCc, STR_MsgBcc, STR_MsgSubject, STR_MsgBody)

Function Send_Msg(STR_SmtpHost, STR_SmtpPort, STR_MsgFrom, STR_MsgTo, STR_MsgCc, STR_MsgBcc, STR_MsgSubject, STR_MsgBody)

Set OBJ_EMail = CreateObject("CDO.Message")

OBJ_EMail.From = STR_MsgFrom
OBJ_EMail.Subject = STR_MsgSubject
OBJ_EMail.TextBody = STR_MsgBody

OBJ_EMail.To = STR_MsgTo
OBJ_EMail.Cc = STR_MsgCc
OBJ_EMail.Bcc = STR_MsgBcc

OBJ_EMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
OBJ_EMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = STR_SmtpHost
OBJ_EMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = STR_SmtpPort

OBJ_EMail.Configuration.Fields.Update
OBJ_EMail.Send

Set OBJ_EMail = Nothing

End Function