通过Powershell发送Outlook 2010电子邮件

时间:2023-01-07 18:16:18

1st of all, in my job, we do not have an Active Directory, and it won't change so soon.

首先,在我的工作中,我们没有Active Directory,它不会那么快改变。

What I am trying to do is, send an e-mail to desired users using HTML. I have this script that I wrote:

我要做的是,使用HTML向所需用户发送电子邮件。我写了这个脚本:

#Variables
$sig = Get-Content "%userprofile%\AppData\Roaming\Microsoft\Assinaturas\html.htm"
$Para = "mail@domain.com.br"
$Assunto = "Teste"
$Conteudo="<html>
<head>
<style>
<!--
@font-face {font-family:Calibri; font-size:11.0pt;}
-->
</style>
</head>
<body>
Line1
<br><br>
&emsp;line 2
<br><br>
&emsp;line 3
<br><br>
<strong><em>Line 4</strong></em>
<br>
Atenciosamente,
<br>
</body>
</html
$sig
"

#Writedatbitchdown
$outl = New-Object -ComObject outlook.application
$email = $outl.CreateItem(0)
$email.display()

$email.To = $Para
$email.Subject = $Assunto

$oldbody = $email.HTMLBody
$newbody = $Conteudo
$newbody += $oldbody
$email.HTMLBody = $newbody

Start-Sleep -s 3
$email.Send()
Start-Sleep -s 5
#Quit
$outl.Quit()
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($outl)
Remove-Variable outl

As you can see, I tried to add signature using Get-content "signatureFile.htm", it doesn't work at all, tried to use default signature and it doesn't work either. I received the e-mail as plain text.

正如您所看到的,我尝试使用Get-content“signatureFile.htm”添加签名,它根本不起作用,尝试使用默认签名,但它也不起作用。我收到的电子邮件是纯文本。

通过Powershell发送Outlook 2010电子邮件

Another situation is the e-mail is sent as HTML and ONLY the image is not shown up.

另一种情况是电子邮件以HTML格式发送,并且只显示图像。

How can I link signature and its images with Outlook 2010? If theres anything not clear, please comment it out and I will try to express myself better.

如何将签名及其图像与Outlook 2010链接?如果有什么不清楚,请评论出来,我会尽力表达自己。

1 个解决方案

#1


0  

If a user already had signature assigned to new emails this code should have worked on its own without $sig. That being said you are trying a add a signature from file which does work with an important change which is the way you are referencing the environment variable %userprofile%. PowerShell does not expand those as is in scripts. The PowerShell way is to use the env: keyword. Consider the following

如果用户已经为新电子邮件分配了签名,则此代码应该在没有$ sig的情况下自行运行。这就是说你正在尝试从文件添加一个签名,它可以处理一个重要的变化,这就是你引用环境变量%userprofile%的方式。 PowerShell不会像脚本那样扩展它们。 PowerShell方法是使用env:关键字。考虑以下

PS C:\Users\mcameron> Get-ChildItem env:

Name                           Value
----                           -----
ALLUSERSPROFILE                C:\ProgramData
APPDATA                        C:\Users\mcameron\AppData\Roaming

In your case your $sig should be something like this:

在你的情况下你的$ sig应该是这样的:

$sig = Get-Content "$($env:appdata)\Microsoft\Signatures\Logo.htm"

As for embedding the image I am not sure at this time but will investigate. As a side note I don't understand the reason for the comment about ActiveDirectory?

至于嵌入图像我目前还不确定,但会进行调查。作为旁注,我不明白有关ActiveDirectory的评论的原因?

#1


0  

If a user already had signature assigned to new emails this code should have worked on its own without $sig. That being said you are trying a add a signature from file which does work with an important change which is the way you are referencing the environment variable %userprofile%. PowerShell does not expand those as is in scripts. The PowerShell way is to use the env: keyword. Consider the following

如果用户已经为新电子邮件分配了签名,则此代码应该在没有$ sig的情况下自行运行。这就是说你正在尝试从文件添加一个签名,它可以处理一个重要的变化,这就是你引用环境变量%userprofile%的方式。 PowerShell不会像脚本那样扩展它们。 PowerShell方法是使用env:关键字。考虑以下

PS C:\Users\mcameron> Get-ChildItem env:

Name                           Value
----                           -----
ALLUSERSPROFILE                C:\ProgramData
APPDATA                        C:\Users\mcameron\AppData\Roaming

In your case your $sig should be something like this:

在你的情况下你的$ sig应该是这样的:

$sig = Get-Content "$($env:appdata)\Microsoft\Signatures\Logo.htm"

As for embedding the image I am not sure at this time but will investigate. As a side note I don't understand the reason for the comment about ActiveDirectory?

至于嵌入图像我目前还不确定,但会进行调查。作为旁注,我不明白有关ActiveDirectory的评论的原因?