{"id":11104,"date":"2018-11-30T12:00:25","date_gmt":"2018-11-30T03:00:25","guid":{"rendered":"https:\/\/www.ka-net.org\/blog\/?p=11104"},"modified":"2018-12-07T14:02:48","modified_gmt":"2018-12-07T05:02:48","slug":"powershellmailkit%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%a1%e3%83%bc%e3%83%ab%e3%81%ab%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e6%b7%bb%e4%bb%98%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=11104","title":{"rendered":"[PowerShell]MailKit\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u6dfb\u4ed8\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>\u5148\u65e5\u3001PowerShell\u304b\u3089<a href=\"https:\/\/www.nuget.org\/packages\/MailKit\/\" title=\"NuGet Gallery | MailKit 2.0.7\" target=\"_blank\">MailKit<\/a>\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u8a18\u4e8b\u3092\u66f8\u304d\u307e\u3057\u305f\u3002<\/p>\n<div class=\"cardlink\"><a href=\"https:\/\/www.ka-net.org\/blog\/?p=11087\"><div class=\"cardlink_thumbnail\"><img src='https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/eyecatch-PowerShell-120x120.png' alt='[PowerShell]MailKit\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u65b9\u6cd5' width=120 height=120 \/><\/a><\/div><div class=\"cardlink_content\"><span class=\"timestamp\">2018.11.28<\/span><div class=\"cardlink_title\"><a href=\"https:\/\/www.ka-net.org\/blog\/?p=11087\">[PowerShell]MailKit\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u65b9\u6cd5 <\/a><\/div><div class=\"cardlink_excerpt\">\uff20IT\u3092\u773a\u3081\u3066\u3044\u305f\u3089\u3001\u6c17\u306b\u306a\u308b\u8a18\u4e8b\u3092\u898b\u304b\u3051\u307e\u3057\u305f\u3002\r\n\r\n\r\n\r\nMailKit\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u9001\u4fe1\u3092\u884c\u3046\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u7d39\u4ecb\u3067\u3059\u304c\u3001\u6c17\u306b\u306a\u3063\u305f\u306e\u306fSmtpClient\u30af\u30e9\u30b9\u306b\u3064\u3044\u3066\u66f8\u304b\u308c\u305f\u90e8\u5206\u3002\r\n\r\n.NET Framework 2.0\u4ee5\u6765\u3001\u30e1\u30fc\u30eb\u9001\u4fe1...<\/div><\/div><div class=\"cardlink_footer\"><\/div><\/div>\n<p>\u524d\u56de\u306f\u30c6\u30ad\u30b9\u30c8\u306e\u307f\u306e\u30e1\u30fc\u30eb\u3060\u3063\u305f\u306e\u3067\u3001\u4eca\u56de\u306f\u30d5\u30a1\u30a4\u30eb\u3092\u6dfb\u4ed8\u3057\u305f\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><span style=\"color: #ff0000; font-weight: bold;\">\u203b MailKit\u306e\u5c0e\u5165\u65b9\u6cd5\u306f\u300c<a href=\"https:\/\/www.ka-net.org\/blog\/?p=11087\" title=\"[PowerShell]MailKit\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u65b9\u6cd5 | \u521d\u5fc3\u8005\u5099\u5fd8\u9332\" target=\"_blank\">[PowerShell]MailKit\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u65b9\u6cd5<\/a>\u300d\u3092\u3054\u53c2\u7167\u304f\u3060\u3055\u3044\u3002<\/span><\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">#DLL\u8aad\u307f\u8fbc\u307f\r\n&#x5B;void]&#x5B;System.Reflection.Assembly]::LoadFile(&quot;C:\\System\\MailKit\\MailKit.dll&quot;)\r\n&#x5B;void]&#x5B;System.Reflection.Assembly]::LoadFile(&quot;C:\\System\\MailKit\\MimeKit.dll&quot;)\r\n\r\n#\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u5909\u66f4\r\n$userID = &quot;xxxx@xxxxxxxxxx.onmicrosoft.com&quot;\r\n$userPassword = &quot;(\u30d1\u30b9\u30ef\u30fc\u30c9)&quot;\r\n$mailServer = &quot;smtp.office365.com&quot;\r\n$mailPort = 587\r\n$mailFromAddress = &quot;xxxx@xxxxxxxxxx.onmicrosoft.com&quot;\r\n$mailFromName = &quot;\u5dee\u51fa\u4eba&quot;\r\n$mailToAddress = &quot;(\u5b9b\u5148\u30a2\u30c9\u30ec\u30b9)&quot;\r\n$mailToName = &quot;\u5b9b\u5148&quot;\r\n$mailSubject = &quot;\u3010\u4ef6\u540d\u3011\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u306e\u9001\u4fe1\u30c6\u30b9\u30c8&quot;\r\n$mailBodyText = &quot;\u30d5\u30a1\u30a4\u30eb\u3092\u6dfb\u4ed8\u3057\u307e\u3059\u3002&quot;\r\n$attachmentFilePath = &quot;C:\\Test\\\u30c6\u30b9\u30c8\u7528PDF.pdf&quot;\r\n\r\n#\u30e1\u30c3\u30bb\u30fc\u30b8\u8a2d\u5b9a\r\n$msg = New-Object MimeKit.MimeMessage\r\n$mailFrom = New-Object MimeKit.MailboxAddress($mailFromName, $mailFromAddress)\r\n$msg.From.Add($mailFrom)\r\n$mailTo = New-Object MimeKit.MailboxAddress($mailToName, $mailToAddress)\r\n$msg.To.Add($mailTo)\r\n$msg.Subject = $mailSubject\r\n$textPart = New-Object MimeKit.TextPart(&#x5B;MimeKit.Text.TextFormat]::Plain)\r\n$textPart.Text = $mailBodyText\r\n\r\n#\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u8a2d\u5b9a\r\n$attachment = New-Object MimeKit.MimePart\r\n$content = New-Object MimeKit.MimeContent(&#x5B;System.IO.File]::OpenRead($attachmentFilePath), &#x5B;MimeKit.ContentEncoding]::Default)\r\n$attachment.Content = $content\r\n$contentDisposition = New-Object MimeKit.ContentDisposition(&#x5B;MimeKit.ContentDisposition]::Attachment)\r\n$attachment.ContentDisposition = $contentDisposition\r\n$attachment.ContentTransferEncoding = &#x5B;MimeKit.ContentEncoding]::Base64\r\n$attachment.FileName = &#x5B;System.IO.Path]::GetFileName($attachmentFilePath)\r\n$multiPart = New-Object MimeKit.Multipart(&quot;mixed&quot;)\r\n$multiPart.Add($textPart)\r\n$multiPart.Add($attachment)\r\n$msg.Body = $multiPart\r\n\r\n#\u30e1\u30fc\u30eb\u9001\u4fe1\r\n$client = New-Object MailKit.Net.Smtp.SmtpClient\r\n$client.Connect($mailServer, $mailPort, $false)\r\n$client.Authenticate($userID, $userPassword)\r\n$client.Send($msg)\r\n$client.Disconnect($true)<\/pre>\n<p><a href=\"https:\/\/www.ka-net.org\/blog\/?p=11087\" title=\"[PowerShell]MailKit\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u65b9\u6cd5 | \u521d\u5fc3\u8005\u5099\u5fd8\u9332\" target=\"_blank\">\u524d\u56de<\/a>\u3068\u540c\u3058\u304f\u3001Office 365\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u304b\u3089\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n<p>\u4e0a\u8a18\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u6307\u5b9a\u3057\u305f\u5b9b\u5148\u306bPDF\u30d5\u30a1\u30a4\u30eb\u4ed8\u304d\u306e\u30e1\u30fc\u30eb\u304c\u9001\u3089\u308c\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/PowerShell_MailKit_02.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/PowerShell_MailKit_02.jpg\" alt=\"\" width=\"906\" height=\"725\" class=\"alignnone size-full wp-image-11105\" srcset=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/PowerShell_MailKit_02.jpg 906w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/PowerShell_MailKit_02-300x240.jpg 300w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/PowerShell_MailKit_02-768x615.jpg 768w\" sizes=\"auto, (max-width: 906px) 100vw, 906px\" \/><\/a><\/p>\n<p>\u30b3\u30fc\u30c9\u306f<a href=\"http:\/\/www.mimekit.net\/docs\/html\/Creating-Messages.htm\" title=\"Creating messages\" target=\"_blank\">\u516c\u5f0f\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/a>\u3092\u53c2\u8003\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u30c6\u30ad\u30b9\u30c8\u90e8\u5206\u3068\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u90e8\u5206\u3092\u5408\u308f\u305b\u305f\u30de\u30eb\u30c1\u30d1\u30fc\u30c8\u5f62\u5f0f\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u3068\u3057\u3066\u3044\u308b\u70b9\u304c\u3001\u524d\u56de\u3068\u5927\u304d\u304f\u7570\u306a\u308a\u307e\u3059\u3002<\/p>\n<h4 class=\"style4a\">\u95a2\u9023\u8a18\u4e8b<\/h4>\n<div class=\"cardlink\"><a href=\"https:\/\/www.ka-net.org\/blog\/?p=11110\"><div class=\"cardlink_thumbnail\"><img src='https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/eyecatch-PowerShell-120x120.png' alt='[PowerShell]MailKit\u3092\u4f7f\u3063\u3066\u30b5\u30fc\u30d0\u30fc\u4e0a\u306e\u30e1\u30fc\u30eb\u3092\u78ba\u8a8d\u3059\u308b\u65b9\u6cd5(POP3)' width=120 height=120 \/><\/a><\/div><div class=\"cardlink_content\"><span class=\"timestamp\">2018.12.07<\/span><div class=\"cardlink_title\"><a href=\"https:\/\/www.ka-net.org\/blog\/?p=11110\">[PowerShell]MailKit\u3092\u4f7f\u3063\u3066\u30b5\u30fc\u30d0\u30fc\u4e0a\u306e\u30e1\u30fc\u30eb\u3092\u78ba\u8a8d\u3059\u308b\u65b9\u6cd5(POP3) <\/a><\/div><div class=\"cardlink_excerpt\">\u5148\u65e5\u304b\u3089MailKit\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u9001\u4fe1\u3092\u884c\u3046PowerShell\u306e\u30b3\u30fc\u30c9\u306b\u3064\u3044\u3066\u8a18\u4e8b\u3092\u66f8\u3044\u3066\u304d\u307e\u3057\u305f\u3002\r\n\r\n\r\n\r\n\r\n\r\n\u4eca\u5ea6\u306f\u30e1\u30fc\u30eb\u9001\u4fe1\u3067\u306f\u306a\u304f\u3001\u53d7\u4fe1\u5074\u306e\u51e6\u7406\u3092\u8a66\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002\r\n\r\n[powershell]#DLL\u8aad\u307f\u8fbc\u307f\r\n[void][S...<\/div><\/div><div class=\"cardlink_footer\"><\/div><\/div>\n<div id=\"single_banner_area2\" class=\"clearfix one_banner\">\n<div class=\"single_banner single_banner_left\">\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\r\n<!-- \u8a18\u4e8b\u4e2d(\u30c7\u30a3\u30b9\u30d7\u30ec\u30a4\u5e83\u544a\u30e6\u30cb\u30c3\u30c8) -->\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:block\"\r\n     data-ad-client=\"ca-pub-7306936664602087\"\r\n     data-ad-slot=\"5429724765\"\r\n     data-ad-format=\"auto\"\r\n     data-full-width-responsive=\"true\"><\/ins>\r\n<script>\r\n     (adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script>\n<\/div>\n<div class=\"single_banner single_banner_right\">\n<a href=\"\" target=\"_blank\"><img decoding=\"async\" src=\"\" alt=\"\" title=\"\" \/><\/a>\n<\/div>\n<\/div>\n\n","protected":false},"excerpt":{"rendered":"\u5148\u65e5\u3001PowerShell\u304b\u3089MailKit\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u8a18\u4e8b\u3092\u66f8\u304d\u307e\u3057\u305f\u3002 \u524d\u56de\u306f\u30c6\u30ad\u30b9\u30c8\u306e\u307f\u306e\u30e1\u30fc\u30eb\u3060\u3063\u305f\u306e\u3067\u3001\u4eca\u56de\u306f\u30d5\u30a1\u30a4\u30eb\u3092\u6dfb\u4ed8\u3057\u305f\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002 \u203b MailKit\u306e\u5c0e [&hellip;]","protected":false},"author":1,"featured_media":7127,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"[[PowerShell]MailKit\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u6dfb\u4ed8\u3059\u308b\u65b9\u6cd5]","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[94],"tags":[],"class_list":["post-11104","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/eyecatch-PowerShell.png","jetpack_shortlink":"https:\/\/wp.me\/p4UZZr-2T6","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/11104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11104"}],"version-history":[{"count":3,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/11104\/revisions"}],"predecessor-version":[{"id":11116,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/11104\/revisions\/11116"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/media\/7127"}],"wp:attachment":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}