将超链接添加到通过PowerShell生成的电子邮件中 [英] Adding a hyperlink to an email generated through PowerShell

查看:57
本文介绍了将超链接添加到通过PowerShell生成的电子邮件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,当前可以执行多项操作.它会在Active Directory中创建一个用户帐户,将数据写入SQL表,然后使用该帐户的用户名和密码将电子邮件发送给帐户请求者.

I have a script that currently does several things. It creates a user account in Active Directory, writes data to a SQL table and sends an email to the account requestor with the account's user name and password.

我们很乐意在该电子邮件中添加一个超链接,以便请求者可以单击以查看其原始请求表单,但是我似乎不太了解语法的正确性.

We'd love to add a hyperlink to that email so that the requestor can click to view their original request form, but I can't quite seem to get the syntax right.

因为在PowerShell语法和HTML链接中使用了双引号,所以我将该链接定义为一个变量,并将该变量插入到电子邮件的-body部分中,以消除双引号的混淆,尽管这可能不必要

Because double quotes are used in the PowerShell syntax as well as the HTML link, I defined the link as a variable and inserted that variable into the -body section of the email to eliminate double quote confusion, though this may not be necessary.

有人可以帮助我在此电子邮件中插入链接吗?非常感谢!

Can anyone help me insert a link in this email? Many thanks!

当前副本:

"The user account you requested (request #$ReqID) has been created."

我们希望$ ReqID超链接到Web表单.

We'd like $ReqID to hyperlink to the Web form.

我定义的变量:

$link = '<a href="http://tsturl/detail.aspx?reqID=$reqID">$ReqID</a>'

但是它在电子邮件正文中的显示如下:

But it displays in the email body like this:

The user account you requested (request #<a href="http://tsturl/detail.aspx?reqID=$reqID">$ReqID</a>) has been created.

帮助?

推荐答案

将您的引号引起来,即:

Swap your quotes around, i.e.:

$link = "<a href='http://tsturl/detail.aspx?reqID=$reqID'>$ReqID</a>"

或者这样做:

$link = '<a href="http://tsturl/detail.aspx?reqID=$reqID">$ReqID</a>'
$link = $ExecutionContext.InvokeCommand.ExpandString($link)

在您的评论之外,如果您希望邮件正文呈现为HTML,从而显示一个链接,那么您需要告诉您的邮件客户端该正文是HTML. $ link 只是一个普通的旧字符串,并且不知道它是HTML.

Further to your comment, if you want the mail body to render as HTML, an thus display a link, then you'll need to tell your mail client that the body is HTML. $link is just a plain old string and doesn't know that it's HTML.

从您的上一个问题中,我猜你是重新使用 Send-MailMessage cmdlet.如果是这样,则需要指定 -BodyAsHtml 开关.

From your previous question, I'm guessing you're using the Send-MailMessage cmdlet. If so then you need to specify the -BodyAsHtml switch.

这篇关于将超链接添加到通过PowerShell生成的电子邮件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆