我有这个代码可以发送一封引用互联网上图片的电子邮件:
private void EmailSheet(PricePushFile ppf)
{
string emailAddr = GetEmailAddressForUnit(ppf.SourceFileName);
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
MailItem mailItem = app.CreateItem(OlItemType.olMailItem);
mailItem.To = emailAddr;
string customer = GetCustomerName(ppf.SourceFileName);
mailItem.Subject = string.Format("PRO*ACT Price Push – {0}", customer);
List<String> htmlBody = new List<string>
{
"<html><body><img src=\"http://www.proactusa.com/wp-content/themes/proact/images/pa_logo_notag.png\" alt=\"Pro*Act logo\" ><p>Your PRO*ACT Price Push report is attached.</p>",
"</body></html>"
};
mailItem.HTMLBody = string.Join(Environment.NewLine, htmlBody.ToArray());
mailItem.Attachments.Add(ppf.SourceFileName);
mailItem.Importance = OlImportance.olImportanceNormal;
mailItem.Display(false);
mailItem.Send(); // This sends the email without a dialog displaying first
}
引用的 png ( http://www.proactusa.com/wp-content/themes/proact/images/pa_logo_notag.png ) 相当大,但是当发送电子邮件时,它被压缩成可怜的小东西:
如何确保图像在电子邮件中显示为全尺寸而不是压缩?
更新
添加显式大小可以正常工作,但首选的“Base64”路由不起作用;我试过这个:
private static String PROACT_LOGO_BINARY =
"iVBORw0KGgoAAAAN. . .2ytlR8BYrxuzvr/AM6ZTOQUGb1+AAAAAElFTkSuQmCC";
. . .
string proactLogoAsBinary = PROACT_LOGO_BINARY;
List<String> htmlBody = new List<string>
{
String.Format("<html><body><img src=\"data:image/png;base64,{0}\" alt=\"Pro*Act logo\" ><p>Your PRO*ACT reports are attached.</p></body></html>", proactLogoAsBinary)
};
mailItem.HTMLBody = string.Join(Environment.NewLine, htmlBody.ToArray());
...我得到一个“损坏的图像”替换图像(小红前)
注意:我通过以下方式获得了二进制文件: