如何使用base64链接发送电子邮件附件中的base64图像?

问题描述 投票:0回答:1

我有base64个图像url,我想将此图像作为电子邮件附件发送,但不起作用。抛出错误PathTooLongException

我的代码:

   System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(Base64urlpath);
   attachment.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
   myMail.Attachments.Add(attachment);

请在system.web.Mail中回答我。

谢谢,

c# asp.net email-attachments ftp-server
1个回答
1
投票
您正在使用的构造函数不接受base64输入,但是需要文件的路径:

public Attachment (string fileName);

参数

fileName字串

包含用于创建此附件的文件路径的字符串。

(引自the documentation

似乎您正在寻找接受Stream的构造函数之一。

将base64编码的图像转换为流的一种可能性是用它创建一个MemoryStream

var imageBytes = Convert.FromBase64String(Base64urlpath); using var stream = new MemoryStream(imageBytes); var attachment = new System.Net.Mail.Attachment(stream);

© www.soinside.com 2019 - 2024. All rights reserved.