6
4

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.

Outlook APIによるメール送信

Last updated at Posted at 2016-09-28

Outlookから定期的にメールを送信する必要がありAPIを調べた。

簡単な例が以下

  var app = new Outlook.Application();
  Outlook.MailItem mail = app.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
  mail.Subject = "タイトル";
  Outlook.AddressEntry currentUser = app.Session.CurrentUser.AddressEntry;
  mail.Body = "本文";
  mail.Recipients.Add("宛先@xx.com");
  mail.Recipients.ResolveAll();
  mail.Send(); 

Application.CreateItem メソッド
https://msdn.microsoft.com/ja-jp/library/office/ff869635.aspx

Outlook.MailItemメソッド
https://msdn.microsoft.com/ja-jp/library/office/ff861252.aspx

利用時はアセンブリを追加
Microsoft.Office.Core


Outlook関係なく送る方法

  MailMessage msg = new MailMessage();
  msg.From = new MailAddress("FROM");
  msg.To.Add(new MailAddress("TO"));
  msg.Subject = "件名";
  msg.Body = "本文";
  System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
  smtp.Host = "ホスト名";//SMTPサーバーを指定
  smtp.Port = 25;//(既定値は25)
  smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
  smtp.Send(msg); 
  msg.Dispose();
  smtp.Dispose();//(.NET Framework 4.0以降)

6
4
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
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?