2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

VB.NETを使用したOutlookメール・予定表の送信

Last updated at Posted at 2019-10-12

#はじめに
社内DBから必要な情報を取得して、
その情報から目的の社員へメールもしくは予定表を自動送信する
ということを行う機会があり、その際のメモを記しています。

メモの内容は、Microsoft Outlook 15.0 Object Library (Outlook 2013) を
使用しましたっていうだけです。

#Object Libraryへの参照設定
[プロジェクト]タブ -> [参照の追加] -> [Microsoft Outlook 15.0 Object Library] -> OK
※Object libraryは、使用しているOfficeのバージョンによって変わります。

#メール・予定表送信
Application object instanceの作成

.vb
Dim oApp As Microsoft.Office.Interop.Outlook._Application
oApp = New Microsoft.Office.Interop.Outlook.Application

Mail Itemの作成

.vb
Dim oMsg As Microsoft.Office.Interop.Outlook._MailItem
oMsg = oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
oMsg.Subject = "件名"
oMsg.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML
oMsg.HTMLBody = "本文"
oMsg.To = "XXX@mail.com"
oMsg.CC = "XXX@mail.com"
oMsg.BCC = "XXX@mail.com"
oMsg.Display() ' 表示する場合
oMsg.Send()    ' 送る場合

AppointmentItemの作成

.vb
Dim mtgCalender As Microsoft.Office.Interop.Outlook._AppointmentItem
mtgCalender = oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem)
mtgCalender.MeetingStatus = Microsoft.Office.Interop.Outlook.OlMeetingStatus.olMeeting
mtgCalender.Subject = "件名"
mtgCalender.Start = New DateTime(yyyy, mm, dd, h, m, s)
mtgCalender.Location = "場所"
mtgCalender.Body = "本文"
mtgCalender.Duration = 60 '設定時間
Dim recipient As Microsoft.Office.Interop.Outlook.Recipient
recipient = mtgCalender.Recipients.Add("XXX@mail.com")
recipient.Type = Microsoft.Office.Interop.Outlook.OlMeetingRecipientType.olRequired ' 必須出席者 olOptionalなら任意
mtgCalender.Display()
mtgCalender.Send()
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?