{"id":2592,"date":"2017-02-23T17:53:56","date_gmt":"2017-02-23T09:53:56","guid":{"rendered":"http:\/\/jason695.why3s.tw\/wordpress\/?p=2592"},"modified":"2017-02-23T17:53:56","modified_gmt":"2017-02-23T09:53:56","slug":"how-to-use-the-microsoft-outlook-object-library-to-send-an-html-formatted-message-by-using-visual-c","status":"publish","type":"post","link":"https:\/\/jason695.why3s.tw\/wordpress\/2017\/02\/23\/how-to-use-the-microsoft-outlook-object-library-to-send-an-html-formatted-message-by-using-visual-c\/","title":{"rendered":"How to use the Microsoft Outlook Object Library to send an HTML formatted message by using Visual C#"},"content":{"rendered":"<p>https:\/\/support.microsoft.com\/zh-tw\/help\/310262\/how-to-use-the-microsoft-outlook-object-library-to-send-an-html-formatted-message-by-using-visual-c<\/p>\n<pre class=\"lang:c# decode:true \">using System;\r\nusing System.Reflection;     \/\/ to use Missing.Value\r\n\/\/ TO DO: If you use the Microsoft Outlook 11.0 Object Library, uncomment the following line.\r\n\/\/ using Outlook = Microsoft.Office.Interop.Outlook;\r\n\r\nnamespace SendHTMLMail\r\n{\r\n   public class Class1\r\n   {\r\n      public static int Main(string[] args)\r\n      {\r\n         try\r\n         {\r\n            \/\/ Create the Outlook application.\r\n            Outlook.Application  oApp = new Outlook.Application();\r\n\r\n            \/\/ Get the NameSpace and Logon information.\r\n            Outlook.NameSpace oNS = oApp.GetNamespace(\"mapi\");\r\n\r\n            \/\/ Log on by using a dialog box to choose the profile.\r\n            oNS.Logon(Missing.Value, Missing.Value, true, true); \r\n\r\n            \/\/ Alternate logon method that uses a specific profile.\r\n            \/\/ TODO: If you use this logon method, \r\n            \/\/  change the profile name to an appropriate value.\r\n            \/\/oNS.Logon(\"YourValidProfile\", Missing.Value, false, true); \r\n\r\n            \/\/ Create a new mail item.\r\n            Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);\r\n\r\n            \/\/ Set the subject.\r\n            oMsg.Subject = \"Send Using OOM in C#\";\r\n\r\n            \/\/ Set HTMLBody.\r\n            String sHtml;\r\n            sHtml = \"&lt;HTML&gt;\\n\" + \r\n               \"&lt;HEAD&gt;\\n\" +\r\n               \"&lt;TITLE&gt;Sample GIF&lt;\/TITLE&gt;\\n\" +\r\n               \"&lt;\/HEAD&gt;\\n\" +\r\n               \"&lt;BODY&gt;&lt;P&gt;\\n\" + \r\n               \"&lt;h1&gt;&lt;Font Color=Green&gt;Inline graphics&lt;\/Font&gt;&lt;\/h1&gt;&lt;\/P&gt;\\n\" +\r\n               \"&lt;\/BODY&gt;\\n\" + \r\n               \"&lt;\/HTML&gt;\";\r\n            oMsg.HTMLBody = sHtml;\r\n\r\n            \/\/ Add a recipient.\r\n            Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;\r\n            \/\/ TODO: Change the recipient in the next line if necessary.\r\n            Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(\"email address\");\r\n            oRecip.Resolve();\r\n\r\n            \/\/ Send.\r\n            oMsg.Send();\r\n\r\n            \/\/ Log off.\r\n            oNS.Logoff();\r\n\r\n            \/\/ Clean up.\r\n            oRecip = null;\r\n            oRecips = null;\r\n            oMsg = null;\r\n            oNS = null;\r\n            oApp = null;\r\n         }\r\n\r\n         \/\/ Simple error handling.\r\n         catch (Exception e)\r\n         {\r\n            Console.WriteLine(\"{0} Exception caught.\", e);\r\n         }  \r\n\r\n         \/\/ Default return value.\r\n         return 0;\r\n  \r\n      }\r\n   }\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/support.microsoft.com\/zh-tw\/help\/310262\/how-to- &hellip; <a href=\"https:\/\/jason695.why3s.tw\/wordpress\/2017\/02\/23\/how-to-use-the-microsoft-outlook-object-library-to-send-an-html-formatted-message-by-using-visual-c\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587 <span class=\"screen-reader-text\">How to use the Microsoft Outlook Object Library to send an HTML formatted message by using Visual C#<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-2592","post","type-post","status-publish","format-standard","hentry","category-net","no-featured-image"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts\/2592","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/comments?post=2592"}],"version-history":[{"count":0,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts\/2592\/revisions"}],"wp:attachment":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/media?parent=2592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/categories?post=2592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/tags?post=2592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}