** **更新发送HTML格式的电子邮件使用PowerShell

所以,我一直在努力构建一个基于PowerShell的通知引擎为喜爱MSFT产品的矿山称为证书生命周期管理器(开玩笑!)。无论如何,我想使电子邮件漂亮的(毕竟,每个人都喜欢漂亮的电子邮件)。要做到这一点,我想最好的方法是发送HTML格式的电子邮件。但是,我不想有电子邮件布局必然嵌入我的PowerShell代码内。

用人谷歌,我四处搜寻。可悲的是,一开始我真的没有看到任何见顶我的兴趣。几乎准备写代码我自己,然后,我发现了一个真正伟大的博客中通过埃里克·麦卡蒂其中有一些代码,做了几乎正是我想要的(万岁!)。

考虑到我喜欢分享,下面是关于来从发布以及相关的XSLT例子功能。此外,我张贴这对PoshCode

**更新**

我做了一些改进,我以前发布的功能。该功能现在是有帮助的模块,可以接受的地址列表,更好的错误处理,等等。这个模块上可以找到PoshCode。要使用这个模块,只是导入模块到你的PowerShell会话使用导入模块小命令(使用PowerShell 2.0 CTP3或更大)。

一旦你的模块进口的,你可以利用的发送-HTMLFormattedEmail小命令。例如:

发送-HTMLFormattedEmail - 要bob@aol.com -ToDisName“鲍勃巴克” - 摘自thepope@vaticancity.va -FromDisName“教皇” -subject“高尔夫时间!”-content“我真的要玩这个星期天,是您18洞?”-Relay smtp.popemail.com -XSLPath “C:\模板\ holymailtemplate.xsl”

再次,对于XSL模板的格式应该如下:

<?XML版本= “1.0”?>

教皇邮件</ TITLE></p> <p></ HEAD></p> <p><BODY></p> <p><DIV宽度= “400像素”></p> <p><P>亲爱的<xsl:选择=值的 “$要”/>,</ P></p> <p><P> </ p></p> <p><P>的<xsl:选择=-的值 “$内容”/> </ p></p> <p><P> </ p></p> <p><地址></p> <p>从您的感谢:<br /></p> <p>圣洁<br /></p> <p></地址></p> <p></ DIV></p> <p></ BODY></p> <p></ HTML></p> <p></ XSL:模板></p> <p></ XSL:样式></p> </blockquote> <p><strong>如果你喜欢这个,看看泰森一些其他职位:</strong></p> <aside class="nativo-promo nativo-promo-1 tablet desktop" id=""></aside> <ul> <li><a href="//m.amiribrahem.com/community/node/40368" rel="nofollow">当一台计算机科学学位的问题,而当它不</a></li> <li><a href="//m.amiribrahem.com/community/node/40337" rel="nofollow">从什么时候起计算成为云/需要的宣言?</a></li> <li><a href="//m.amiribrahem.com/community/node/39835" rel="nofollow">为什么一个钓鱼用诱饵证书颁发机构(CA)?</a></li> <li><a href="//m.amiribrahem.com/community/node/38537" rel="nofollow">我会信任你,如果每个人都信任你?</a></li> <li><a href="//m.amiribrahem.com/community/node/38431" rel="nofollow">这里是一个很好的问题:是脚本编程或者只是系统管理?</a></li> <li><a href="//m.amiribrahem.com/community/node/37444" rel="nofollow">PowerShell的男孩和失踪的cmdlet的情况下!</a></li> <li><a href="//m.amiribrahem.com/community/node/36616" rel="nofollow">有趣的使用PowerShell 2.0三项​​赛!</a></li> <li><a href="//m.amiribrahem.com/community/node/35300" rel="nofollow">创建ASP.NET Web应用程序自定义404页,手柄链接重定向</a></li> </ul> <p><strong>或者,如果你愿意,你还可以检查出一些泰森的最新出版物:</strong></p> <ul> <li><a href="http://www.amazon.com/Windows-PowerShell-Unleashed-Tyson-Kopczynski/dp/0672329883" rel="nofollow">Windows PowerShell中偷跑(2<sup>ND</sup>版)</a></li> <li><a href="http://www.amazon.com/Windows-Server-2008-Unleashed-Morimoto/dp/0672329301/ref=pd_cp_b_2?pf_rd_p=413864201&pf_rd_s=center-41&pf_rd_t=201&pf_rd_i=0672329883&pf_rd_m=ATVPDKIKX0DER&pf_rd_r=04095KXYFH72ARAKZ0QY" rel="nofollow">Windows Server 2008的偷跑</a>(是的,我确实帮助这本书)</li> </ul> <p><strong>最后,请访问<a href="//m.amiribrahem.com/subnets/microsoft/" rel="nofollow">微软子网</a>更多新闻,博客,以及来自各地的网络舆论。或者,报名参加<a href="//m.amiribrahem.com/nl/signup.jsp">双周微软通讯</a>。(点击新闻/微软新闻快讯)</strong></p> <div class="end-note"> <!-- blx4 #2005 blox4.html --> <div id="" class="blx blxParticleendnote blxM2005 blox4_html blxC23909"> 加入对网络世界的社有个足球雷竞技app区<a href="https://www.facebook.com/NetworkWorld/" target="_blank">Facebook的</a>和<a href="https://www.linkedin.com/company/network-world" target="_blank">LinkedIn</a>对那些顶级心态的话题发表评论。</ DIV></ DIV></ DIV><div class="apart-alt tags"> <span class="related">有关:</span> <ul> <li><a class="edition-link-url primary-cat-url2" href="//m.amiribrahem.com/category/microsoft"><span class="primary-cat-name2">微软</span></a></li> <li><a class="edition-link-url" href="//m.amiribrahem.com/tag/powershell/" rel="nofollow">电源外壳</a></li> </ul> </div> <p class="content-copy">©2009<span class="ccbu">Raybet2</span></p> <!-- blx4 #1524 blox4.article.toaster --> <div class="article-intercept"> <a href="https://www.idginsiderpro.com/article/3526496/it-salary-survey-2020-the-results-are-in.html"><i class="ss-icon ss-navigateright"></i><em>IT薪资调查:</em>结果是</a> </div> <style> @media only screen and (min-width: 60.625em) { article .apart.ad.not-lazy { margin-left: 0; float: right; } } /* this spaces the ads in the right rail */ @media only screen and ( min-width: 48em ) { article #drr-top-ad.epo.cat-narrow #imu2 { margin-top: 390px; /*originally 354px*/ } .topDeals.topper { margin-top: 390px; } } @media only screen and ( min-width: 48em ) and ( max-width: 58.063em ) { article #drr-top-ad.epo.cat-narrow #imu2 { margin-top: 0; } } @media only screen and ( min-width: 60.625em ) { article #drr-top-ad.epo.cat-narrow #imu2 { margin-top: 390px; /*originally 354px*/ } .topDeals.topper { margin-top: 390px; } } @media only screen and ( min-width: 48em ) { article #drr-top-ad.epo.cat-narrow div[id^=imu] { margin-top: 390px; } } @media only screen and ( min-width: 48em ) and ( max-width: 58.063em ) { article #drr-top-ad.epo.cat-narrow div[id^=imu] { margin-top: 0; } } @media only screen and ( min-width: 60.625em ) { article #drr-top-ad.epo.cat-narrow div[id^=imu] { margin-top: 390px; } } </style> </section> <!-- /.bodee --> <div id="content-recommender"> <div class="OUTBRAIN" data-widget-id="AR_1" data-ob-template="NetworkWorld"></div> </div> <div class="lazyload_ad"> <code type="text/javascript"> <!-- var slotName = 'bottomleaderboard'; var slotSize = []; if ($thm.deviceClass == 'mobile') { slotSize = [[300,50],[320,50],[300,250]]; } else if ($thm.deviceClass == 'tablet') { slotSize = [[728,90],[468,60]]; } else { slotSize = [[728,90],[970,90],[970,250]]; } IDG.GPT.addDisplayedAd(slotName, "true"); document.write('<div id="' + slotName + '" class="ad-container">'); consent.ads.queue.push(function(){ IDG.GPT.defineGoogleTagSlot(slotName, slotSize, false, true);}); document.write('</div>'); consent.ads.queue.push(function(){ $('#' + slotName).responsiveAd({screenSize:'971 1115', scriptTags: []}, true);}); //--></code> </div> <link rel="stylesheet" href="//m.amiribrahem.com/www.idgcsmb/css/tso-links.css?v=20200723112743"> <div id="tso-wrapper"> <div id="tso" style="display:none"></div> </div> </article> </section> <!-- /role=main --> </div> <!-- /#page-wrapper --> <link rel="stylesheet" href="//m.amiribrahem.com/www.idge/css/foot.css?v=20200723112743"> <link rel="stylesheet" href="//m.amiribrahem.com/www.idge.nww/css/foot.css?v=20200723112743"> <footer> <section class="brand" itemscope itemtype="http://schema.org/Organization"> <a href="//m.amiribrahem.com/"><span class="logo">有个足球雷竞技app</span></a> <span class="tagline"></span> <span class="follow"><label>跟着我们</label> <ul> <li class="lnkdn"><a class="social-media-li-foot" href="http://www.linkedin.com/company/network-world" itemprop="sameAs" rel="nofollow" target="_blank" onclick="brandFollowTrack('LinkedIn')"><i class="ss-icon ss-social-circle brand ss-linkedin"></i></a></li> <li><a class="social-media-tw-foot" href="https://twitter.com/networkworld" itemprop="sameAs" rel="nofollow" target="_blank" onclick="brandFollowTrack('Twitter')"><i class="ss-icon ss-social-circle ss-twitter"></i></a></li> <li><a class="social-media-fb-foot" href="https://www.facebook.com/NetworkWorld/" itemprop="sameAs" rel="nofollow" target="_blank" onclick="brandFollowTrack('Facebook')"><i class="ss-icon ss-social-circle brand ss-facebook"></i></a></li> </ul></span> </section> <section class="topics"></section> <section class="about"> <div class="wrapper"> <nav class="tertiary" id="ft3"> <ul> <li><a class="edition-link-url" href="//m.amiribrahem.com/about/about.html">关于我们</a></li> <li><a class="edition-link-url" href="//m.amiribrahem.com/about/contactus.html">联系</a></li> <li><a class="edition-link-url" href="//m.amiribrahem.com/about/privacy.html">隐私政策</a></li> <li><a class="edition-link-url" href="//m.amiribrahem.com/about/cookie-policy.html">rayapp </a></li> <li><a class="edition-link-url" href="//m.amiribrahem.com/about/member-preferences.html">dota2雷竞技 </a></li> <li><a class="edition-link-url" href="//m.amiribrahem.com/about/contactus.html">广告</a></li> <li><a class="edition-link-url" href="https://www.idg.com/work-here/" target="_blank" rel="nofollow">IDG招聘</a></li> <li><a class="edition-link-url" href="//m.amiribrahem.com/about/adchoices.html">lol滚球 雷竞技 </a></li> <li><a class="edition-link-url" href="//m.amiribrahem.com/about/affiliates.html">电子商务链接</a></li> <li><a class="edition-link-url" href="//m.amiribrahem.com/about/ccpa.html">加利福尼亚州:不卖我的个人信息</a></li> </ul> </nav> </div> </section> <section class="copyright"> <div class="wrapper"> <img src="https://alt.idgesg.net/images/logos/logo-footer-black.png" alt="IDG通信"> <p><a href="//m.amiribrahem.com/about/copyright.html">版权</a>©2020<span class="bu">Raybet2</span></p> <div class="network"> <div id="network-selector"> <div class="label"> 探索IDG网络<i class="ss-icon tick">降序</i> </div> <ul> <li><a href="https://www.cio.com" target="_blank" rel="nofollow">CIO</a></li> <li><a href="https://www.computerworld.com" target="_blank" rel="nofollow">计算机世界</a></li> <li><a href="https://www.csoonline.com" target="_blank" rel="nofollow">CSO在线</a></li> <li><a href="https://www.infoworld.com" target="_blank" rel="nofollow">InfoWorld的</a></li> <li><a href="//m.amiribrahem.com" target="_blank" rel="nofollow">有个足球雷竞技app</a></li> </ul> </div> <!-- /#network-selector --> </div> <!-- /.network --> </div> <!-- /.wrapper --> </section> </footer> <div id="mobilewelcomead" class=" ad-container test"></div> <div id="catfish" class=" ad-container test"></div> <!-- Begin gpt-skin --> <div id="gpt-skin" class=" ad-container"></div> <!-- End gpt-skin --> <!-- Include here when empty article and when not empty and article is slideshow as this script is included with DRR code in body-base.jsp. --> <!-- Also do not include on search page with new right rail. OC-1778 --> <!-- Begin comScore Tag --> <noscript> <img src="https://sb.scorecardresearch.com/p?c1=2&c2=6035308&cv=2.0&cj=1"> </noscript> <!-- End comScore Tag --> <!-- LiveRamp Sources --> <!-- End of LiveRamp --> <div id="loginModal"></div> <div id="logoffModal"></div> </body> </html>