如何使用Powershell从Sharepoint以HTML电子邮件的形式发送内联图像. [英] How to send Inline images from Sharepoint as HTML email using powershell.
问题描述
如何使用Powershell从Sharepoint以HTML电子邮件的形式发送内联图像.
How to send Inline images from Sharepoint as HTML email using powershell.
我在下面胆怯,一切正常,期望图像未显示在电子邮件中.
I treid below,everything works fine expect image is not showing in email.
函数GetUserEmail($ UserValue)
{
$ arr = $ UserValue.Split(;#");
$ UserID = $ arr [0];
$ user = $ web.SiteUsers.GetById($ UserId);
返回$ user.Email
}
函数GetUserName($ UserValue)
{
$ arr = $ UserValue.Split(;#");
$ UserID = $ arr [0];
$ user = $ web.SiteUsers.GetById($ UserId);
返回$ user.DisplayName
}
$ web = Get-SPWeb -Site http://test.domain.com/
$ siteUrl =" http://test.domain.com/"
$ listName =生日"
$ site =新对象Microsoft.SharePoint.SPSite($ siteUrl)
$ web = $ site.OpenWeb()
$ list = $ web.Lists [$ listName];
$ date_currentdate =(Get-Date).ToString("MMdd"))
Function GetUserEmail($UserValue)
{
$arr = $UserValue.Split(";#");
$UserID = $arr[0];
$user = $web.SiteUsers.GetById($UserId);
return $user.Email
}
Function GetUserName($UserValue)
{
$arr = $UserValue.Split(";#");
$UserID = $arr[0];
$user = $web.SiteUsers.GetById($UserId);
return $user.DisplayName
}
$web = Get-SPWeb -Site http://test.domain.com/
$siteUrl = "http://test.domain.com/"
$listName = "Birthdays"
$site = new-object Microsoft.SharePoint.SPSite($siteUrl)
$web = $site.OpenWeb()
$list = $web.Lists[$listName];
$date_currentdate=(Get-Date).ToString("MMdd")
foreach($ list.Items中的$ item)
{
if($ item ["DateofBirth"] -ne $ null)
{
$ scheddate = $ item ["DateofBirth"]
if($ date_currentdate -eq $ scheddate.ToString("MMdd"))
{
$ emailobj =新对象System.Collections.Specialized.StringDictionary
$ string = $ item ['BirthdayCard']
$ ImageURL,$ b = $ string.split(',')
[string] $ bodytext ="
$ EmployeeMail = GetUserEmail($ item [" Employee]])
$ Employeename = GetUserName($ item [" Employee"]]
$ SubjectText ="生日快乐-" + $ Employeename +" !!"
$ bodytext + = $ item ['电子邮件说明'] +''</br></br>< img src ='" + $ ImageURL +"'/></br></br>"
$ emailobj.Add("to",$ EmployeeMail)
$ emailobj.Add(来自"," a@domain.com ")
$ emailobj.Add("subject",$ SubjectText)
$ bodytext + =< br/>谢谢&关于"br/test",
$ emailobj.Add("content-type","text/html")
[Microsoft.SharePoint.Utilities.SPUtility] :: SendEmail($ web,$ emailobj,$ bodytext)
}
}
}
foreach($item in $list.Items)
{
if ($item["DateofBirth"] -ne $null)
{
$scheddate=$item["DateofBirth"]
if($date_currentdate -eq $scheddate.ToString("MMdd"))
{
$emailobj = New-Object System.Collections.Specialized.StringDictionary
$string = $item['BirthdayCard']
$ImageURL,$b = $string.split(',')
[string]$bodytext=""
$EmployeeMail = GetUserEmail($item["Employee"])
$Employeename = GetUserName($item["Employee"])
$SubjectText="Happy birthday-"+$Employeename+"!"
$bodytext+=$item['EMail Description']+"</br></br><img src='"+$ImageURL+"'/></br></br>"
$emailobj.Add("to", $EmployeeMail)
$emailobj.Add("from", "a@domain.com")
$emailobj.Add("subject",$SubjectText )
$bodytext+="<br/>Thanks & Regards,<br/><br/>test test"
$emailobj.Add("content-type", "text/html")
[Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($web, $emailobj, $bodytext)
}
}
}
图片网址: http://test.domain.com/ 下面是图像在外观上的显示方式.
Below is how image getting displayed in Out look.
感谢与问候,克里希纳
推荐答案
使用相同的域帐户作为您的发件人"帐户,否则图像将被阻止.
测试脚本.
Function GetUserEmail(
UserValue) {UserValue) {
arr =
这篇关于如何使用Powershell从Sharepoint以HTML电子邮件的形式发送内联图像.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!