{"id":10561,"date":"2018-07-06T12:00:12","date_gmt":"2018-07-06T03:00:12","guid":{"rendered":"https:\/\/www.ka-net.org\/blog\/?p=10561"},"modified":"2022-01-12T23:52:28","modified_gmt":"2022-01-12T14:52:28","slug":"powershell%e3%83%a1%e3%83%bc%e3%83%ab%e9%80%81%e4%bf%a1%e7%94%a8%e9%96%a2%e6%95%b0","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=10561","title":{"rendered":"[PowerShell]\u30e1\u30fc\u30eb\u9001\u4fe1\u7528\u95a2\u6570"},"content":{"rendered":"<p>\u672c\u8a18\u4e8b\u3067\u4f7f\u7528\u3057\u3066\u3044\u308bSmtpClient\u306f2018\u5e74\u73fe\u5728\u975e\u63a8\u5968\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n\u4e0b\u8a18\u8a18\u4e8b\u3067\u7d39\u4ecb\u3057\u3066\u3044\u308bMailKit\u3092\u3054\u4f7f\u7528\u304f\u3060\u3055\u3044\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<hr \/>\n<p>PowerShell\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u9001\u4fe1\u3059\u308b\u6a5f\u4f1a\u304c\u5897\u3048\u3066\u304d\u305f\u306e\u3067\u3001\u51e6\u7406\u3092\u95a2\u6570\u5316\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">function sendMail(\r\n    $UserID,                            #\u30e6\u30fc\u30b6\u30fcID\r\n    $UserPassword,                      #\u30d1\u30b9\u30ef\u30fc\u30c9\r\n    $MailFrom,                          #From\r\n    $MailToAry,                         #To(\u914d\u5217\u3067\u6307\u5b9a)\r\n    $MailCcAry,                         #Cc(\u914d\u5217\u3067\u6307\u5b9a)\r\n    $MailBccAry,                        #Bcc(\u914d\u5217\u3067\u6307\u5b9a)\r\n    $MailSubject,                       #\u4ef6\u540d\r\n    $MailBody,                          #\u672c\u6587\r\n    $MailAtthPathAry,                   #\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30b9(\u914d\u5217\u3067\u6307\u5b9a)\r\n    $MailEncoding = &quot;utf-8&quot;,            #\u672c\u6587\u3068\u4ef6\u540d\u306e\u30a8\u30f3\u30b3\u30fc\u30c9\r\n    $MailServer = &quot;smtp.office365.com&quot;, #\u30e1\u30fc\u30eb\u30b5\u30fc\u30d0\u30fc\r\n    $MailPort = 587,                    #\u30dd\u30fc\u30c8\u756a\u53f7\r\n    $SSLFlg = $true                     #SSL\u3092\u4f7f\u7528\u3059\u308b\u304b\u3069\u3046\u304b\u3092\u6307\u5b9a\r\n  ){\r\n  \r\n  #Message\r\n  $Msg = New-Object System.Net.Mail.MailMessage\r\n  $Msg.From = $MailFrom\r\n  foreach($MailTo in $MailToAry){\r\n    $Msg.To.Add($MailTo)\r\n  }\r\n  if($MailCcAry -is &#x5B;array]){\r\n    foreach($MailCc in $MailCcAry){\r\n      $Msg.CC.Add($MailCc)\r\n    }\r\n  }\r\n  if($MailBccAry -is &#x5B;array]){\r\n    foreach($MailBcc in $MailBccAry){\r\n      $Msg.Bcc.Add($MailBcc)\r\n    }\r\n  }\r\n  $Msg.Subject = $MailSubject\r\n  $Msg.SubjectEncoding = &#x5B;System.Text.Encoding]::GetEncoding($MailEncoding);\r\n  $Msg.Body = $MailBody\r\n  $Msg.BodyEncoding = &#x5B;System.Text.Encoding]::GetEncoding($MailEncoding);\r\n  if($MailAtthPathAry -is &#x5B;array]){\r\n    foreach($MailAtthPath in $MailAtthPathAry){\r\n      if(&#x5B;System.IO.File]::Exists($MailAtthPath)){\r\n        $MailAtth = New-Object System.Net.Mail.Attachment($MailAtthPath)\r\n        $Msg.Attachments.Add($MailAtth)\r\n      }\r\n    }\r\n  }\r\n  \r\n  #Server\r\n  $Smtp = New-Object System.Net.Mail.SmtpClient($MailServer, $MailPort)\r\n  $Smtp.Credentials = New-Object System.Net.NetworkCredential($UserID, $UserPassword)\r\n  $Smtp.EnableSsl = $SSLFlg\r\n  $Smtp.Send($Msg)\r\n  \r\n  $Msg.Dispose()\r\n  $Smtp.Dispose()\r\n  return\r\n}\r\n\r\nsendMail &quot;user@hogehogexxx.onmicrosoft.com&quot; &quot;passxxxx&quot; &quot;from@hogehogexxx.onmicrosoft.com&quot; @(&quot;to@hogehogexxx.onmicrosoft.com&quot;) &quot;&quot; &quot;&quot; &quot;\u30c6\u30b9\u30c8\u30e1\u30fc\u30eb&quot; &quot;\u672c\u65871`r`n\u672c\u65872&quot; @(&quot;C:\\Test\\Test1.docx&quot;, &quot;C:\\Test\\Test2.docx&quot;)<\/pre>\n<p><a href=\"https:\/\/docs.microsoft.com\/ja-jp\/powershell\/module\/microsoft.powershell.utility\/send-mailmessage\" title=\"Send-MailMessage\" target=\"_blank\" rel=\"noopener\">Send-MailMessage<\/a>\u30b3\u30de\u30f3\u30c9\u30ec\u30c3\u30c8\u306e\u65b9\u304c\u7c21\u5358\u306a\u306e\u3067\u3059\u304c\u3001\u7d30\u304b\u304f\u5236\u5fa1\u3067\u304d\u308b<a href=\"https:\/\/msdn.microsoft.com\/ja-jp\/library\/system.net.mail.smtpclient.aspx\" title=\"SmtpClient \u30af\u30e9\u30b9 (System.Net.Mail)\" target=\"_blank\" rel=\"noopener\">SmtpClient<\/a>\u30af\u30e9\u30b9\u306e\u65b9\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u6a19\u6e96\u3067\u306fOffice 365\u306e\u30b5\u30fc\u30d0\u30fc\u304b\u3089\u30e1\u30fc\u30eb\u9001\u4fe1\u3059\u308b\u3088\u3046\u306b\u521d\u671f\u5024\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\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<h4 class=\"style4a\">\u53c2\u8003Web\u30da\u30fc\u30b8<\/h4>\n<ul>\n<li>\u3010PowerShell\u3011Windows PowerShell \u3092\u4f7f\u7528\u3057\u3066 GMail \u3084 Office 365 \u304b\u3089\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b<\/li>\n<li style=\"list-style-type:none;\"><a href=\"https:\/\/blogs.technet.microsoft.com\/junichia\/2011\/12\/08\/powershellwindows-powershell-gmail-office-365\/\" target=\"_blank\" title=\"\u3010PowerShell\u3011Windows PowerShell \u3092\u4f7f\u7528\u3057\u3066 GMail \u3084 Office 365 \u304b\u3089\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\" rel=\"noopener\">https:\/\/blogs.technet.microsoft.com\/junichia\/2011\/12\/08\/powershellwindows-powershell-gmail-office-365\/<\/a><\/li>\n<li>SmtpClient\u30af\u30e9\u30b9\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b<\/li>\n<li style=\"list-style-type:none;\"><a href=\"https:\/\/dobon.net\/vb\/dotnet\/internet\/smtpclient.html\" target=\"_blank\" title=\"SmtpClient\u30af\u30e9\u30b9\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\" rel=\"noopener\">https:\/\/dobon.net\/vb\/dotnet\/internet\/smtpclient.html<\/a><\/li>\n<li>CC\u3001BCC\u3001\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u3001\u512a\u5148\u9806\u4f4d\u306a\u3069\u3092\u6307\u5b9a\u3057\u3066\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b<\/li>\n<li style=\"list-style-type:none;\"><a href=\"https:\/\/dobon.net\/vb\/dotnet\/internet\/smtpmail2.html\" target=\"_blank\" title=\"CC\u3001BCC\u3001\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u3001\u512a\u5148\u9806\u4f4d\u306a\u3069\u3092\u6307\u5b9a\u3057\u3066\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\" rel=\"noopener\">https:\/\/dobon.net\/vb\/dotnet\/internet\/smtpmail2.html<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u672c\u8a18\u4e8b\u3067\u4f7f\u7528\u3057\u3066\u3044\u308bSmtpClient\u306f2018\u5e74\u73fe\u5728\u975e\u63a8\u5968\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002 \u4e0b\u8a18\u8a18\u4e8b\u3067\u7d39\u4ecb\u3057\u3066\u3044\u308bMailKit\u3092\u3054\u4f7f\u7528\u304f\u3060\u3055\u3044\u3002 PowerShell\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u9001\u4fe1\u3059\u308b\u6a5f\u4f1a\u304c\u5897\u3048\u3066\u304d\u305f\u306e\u3067\u3001\u51e6\u7406\u3092\u95a2\u6570\u5316\u3057\u3066\u307f\u307e [&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":"\u6bce\u56de\u51e6\u7406\u3092\u66f8\u304f\u306e\u304c\u9762\u5012\u304f\u3055\u3044\u306e\u3067\u95a2\u6570\u5316\u3057\u3066\u307f\u307e\u3057\u305f\u3002 [[PowerShell]\u30e1\u30fc\u30eb\u9001\u4fe1\u7528\u95a2\u6570]","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-10561","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-2Kl","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10561","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=10561"}],"version-history":[{"count":3,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10561\/revisions"}],"predecessor-version":[{"id":14353,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10561\/revisions\/14353"}],"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=10561"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10561"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10561"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}