我有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
中回答我。
谢谢,
public Attachment (string fileName);
参数
fileName
字串包含用于创建此附件的文件路径的字符串。
似乎您正在寻找接受Stream
的构造函数之一。
将base64编码的图像转换为流的一种可能性是用它创建一个MemoryStream
:
var imageBytes = Convert.FromBase64String(Base64urlpath);
using var stream = new MemoryStream(imageBytes);
var attachment = new System.Net.Mail.Attachment(stream);