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

我有import numpy as np # compute the positions here # proper scaling (500000) is applied to the original positions .. # .. obtained from xxx_layout() to get good spreading pos1 = nx.spring_layout(G1,scale=500000,center=[mx1,my1]) pos2 = nx.circular_layout(G2,center=[mx2,my2]) nx.draw_networkx(G1,pos=pos1,node_size=100,node_color='green') nx.draw_networkx(G2,pos=pos2,node_color='red') # # (more code below this line) 个图片网址,我想将此图片作为电子邮件附件发送,但无法正常工作。抛出错误base64

我的代码:

pathtoolongexception

请在 System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(Base64urlpath); attachment.TransferEncoding = System.Net.Mime.TransferEncoding.Base64; myMail.Attachments.Add(attachment); 中回答我。

谢谢

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

您使用的构造函数不接受base64输入,但需要文件路径:

  

public Attachment (string fileName);

     

参数

     

fileName       字符串

     

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

(引自the documentation)。而且,由于您的编码图像长于260个字符,因此您会得到例外,即路径太长。

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

将base64编码的图像转换为流的一种可能性是在其中创建MemoryStream

var imageBytes = Convert.FromBase64String(Base64urlpath);
using var stream = new MemoryStream(imageBytes);
var attachment = new System.Net.Mail.Attachment(stream,null); // you may want to provide a name here
本文链接:https://www.f2er.com/3146581.html

大家都在问