1
1

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.

【C#】メールをHTML形式で送信【Outlook】

Last updated at Posted at 2019-07-30

概要

タイトルまんま。
OutlookをC#で動かして、HTML形式でメールを送る。
(ハイパーリンクを使いたかったのだが、検索してもなかなか使い方がわからなかった。検索の仕方が悪いのか…)
自分用の備忘録に

コード

using System;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace HTMLsample
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Outlook.Application outlookApp = new Outlook.Application();
                Outlook.MailItem mail = outlookApp.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
                mail.Subject = "HTMLsample";
                Outlook.AddressEntry User = outlookApp.Session.CurrentUser.AddressEntry;

                String sHtml;
                sHtml = "<HTML>\n" +
                   "<HEAD>\n" +
                   "<TITLE>Sample GIF</TITLE>\n" +
                   "</HEAD>\n" +
                   "<BODY>\n" +
                   "<p><a href=\"hogehoge\">foofoo</a></p>\n" +
                   "</BODY>\n" +
                   "</HTML>";
                mail.HTMLBody = sHtml;

                mail.Recipients.Add("送信先");
                mail.Recipients.ResolveAll();
                mail.Send();
            }
            catch
            {
                Console.WriteLine("メールは送信できませんでした");
            }
        }
    }
}


以上。
テキストエディタでHTML書いて、それをコピペしても上手くいかなかった。
この書き方なら反映される。なぜ???

↓参考にした
https://support.microsoft.com/en-us/help/310262/how-to-use-the-microsoft-outlook-object-library-to-send-an-html-format

1
1
2

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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?