当前位置: 首页 > 知识库问答 >
问题:

是否可以像Outlook RTF/TNEF那样在html电子邮件中嵌入非图像附件?

谭宜
2023-03-14
  • 这似乎很难,而且
  • 我的电子邮件内容是html格式的,所以我必须首先将RTF转换为html格式。

共有1个答案

方琦
2023-03-14

我决定不那么懒,自己试试...

答案是肯定的,您可以使用引用html电子邮件中的非图像附件。标记和Outlook将打开它们。我使用Outlook 2013作为我的电子邮件客户端,使用Office365作为我的服务器;里程数随客户机和服务器的不同而不同。但如果不使用Outlook就不会很好地工作...

Gmail

下面是我使用EWS进行测试的powershell。它发送一个html电子邮件

PowerShell:

$to1 = 'your-email@gmail.com'
$to2 = 'your-email@your-domaincom'
$subject = 'Test email with embedded attachments'
$body = '
This email shows embedded attachments. Yay. <br/><br/>
Here is an image: <img src="cid:img1@your-domain.com" /><br/>
More amazingly, <a href="cid:att1@your-domain.com">here</a> is a pdf.<br/>
And <a href="cid:att2@your-domain.com">here</a> is a word doc!<br/><br/>
'
# fyi - the '@your-domain.com' in the id is optional but somewhere I read 
# that email clients might like it more if it's included. Doesn't need to 
# be a real domain.

# change these paths to something that exists
$image1Path = "C:\temp\an_image.jpg"
$attachment1Path = "C:\temp\some_file.pdf"
$attachment2Path = "C:\temp\some_doc.docx"

#prompt for Office365 creds
$Credential = Get-Credential

#Load the EWS Managed API Assembly - you need it installed first!!
Add-Type -Path 'C:\Program Files (x86)\Microsoft\Exchange\Web Services\2.1\Microsoft.Exchange.WebServices.dll'

#Instantiate the EWS service object                  
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService

#Set the credentials for Exchange Online
$service.Credentials = New-Object Microsoft.Exchange.WebServices.Data.WebCredentials -ArgumentList  $Credential.UserName, $Credential.GetNetworkCredential().Password

#Autodiscover doesn't seem to work for my office365; set it manually
$service.Url = 'https://outlook.office365.com/EWS/Exchange.asmx'
#This might work for you instead: 
# $service.AutodiscoverUrl($Credential.UserName, {$true})

#Create the email message and set the Subject and Body
$message = New-Object Microsoft.Exchange.WebServices.Data.EmailMessage -ArgumentList $service
$message.Subject = $subject
$message.Body = $body
$null = $message.ToRecipients.Add($to1)
$null = $message.ToRecipients.Add($to2)
$att = $message.Attachments.AddFileAttachment($image1Path)
$att.ContentId = 'img1@your-domain.com'
$att.IsInline=$true
$att = $message.Attachments.AddFileAttachment($attachment1Path)
$att.ContentId = 'att1@your-domain.com'
$att.IsInline=$true
$att = $message.Attachments.AddFileAttachment($attachment2Path)
$att.ContentId = 'att2@your-domain.com'
$att.IsInline=$false

# add the same attachment again with a different name to see if it's 
# rendered differently.
$att = $message.Attachments.AddFileAttachment('no_cid.docx', $attachment2Path)
$att.IsInline=$false

#Send the message and save a copy in the Sent Items folder
$message.SendAndSaveCopy()

 类似资料:
  • 问题内容: 我正在尝试发送包含嵌入式gif图像的多部分/相关html电子邮件。该电子邮件是使用Oracle PL / SQL生成的。我的尝试失败了,图片显示为红色X(在Outlook 2007和yahoo邮件中) 我已经发送HTML电子邮件已有一段时间了,但是我现在的要求是在电子邮件中使用多个gif图像。我可以将它们存储在我们的一台Web服务器上并仅链接到它们,但是许多用户的电子邮件客户端不会自动

  • 问题内容: 我需要在电子邮件中嵌入图像。我该怎么做? 我既不想使用第三方工具,也不想对特定于语言的答案感兴趣(但是如果您想知道的话,它就是PHP)。 我只对生成的电子邮件正文的格式感兴趣。 问题答案: 如您所知,作为电子邮件传递的所有内容都必须文本化。 您必须创建包含多部分/ mime消息的电子邮件。 如果要添加物理图像,则该图像必须使用base 64编码并分配了Content-ID(cid)。如

  • 我正在尝试在电子邮件中嵌入一个图像。我遵循了这里,这里和这里的例子和其他但我不能得到图像显示。 当我执行这个时,我得到的是一个空空如也的身体,里面有一个红十字,没有任何图像。如何使图像与电子邮件正文内联显示? 我正在使用Outlook 2016。我知道我可以在使用Outlook时插入图片,我也收到过别人在文本中插入图片的“正常”电子邮件,所以这肯定意味着我必须能够查看python脚本生成的图片?

  • 问题内容: 有没有办法将图像附加到用PHP创建的html格式的电子邮件中? 我们需要确保在发送给可能在阅读电子邮件时无法访问Internet的客户的电子邮件上带有公司徽标(显然,他们可以下载文件)。 问题答案: 尝试使用PEARMail_Mime软件包,该软件包可以为您嵌入图像。 您需要使用addHTMLImage()方法并传递内容ID(cid),这是一个唯一的文本字符串,您还将在img的src属

  • 我正在做一个项目,所有的团队成员都在使用Eclipse,而我是唯一的IDEA用户。这造成了大量进口重新安排的噪音。eclipse导入的顺序是:Java、Javax、Org、Com,按字母顺序排列。是否可以配置IDEA来遵循这些规则?

  • 我一直在寻找将图像嵌入到与Laravel一起发送的电子邮件中的方法。我发现大多数人使用的方法是将图像作为附件嵌入。 有没有一种方法可以嵌入一个没有附件的图像?我尝试将图像转换为bas64字符串,但这甚至不起作用。