[英]How to resize embedded images in email
我有以下一段工作正常的代碼,能夠發送帶有附件的電子郵件。
我正在嘗試將圖像調整為100px;
寬度100px;
msg.IsBodyHtml = true;
Attachment inlineLogo = new Attachment(@"C:\Desktop\Image.jpg");
msg.Attachments.Add(inlineLogo);
string contentID = "Image";
inlineLogo.ContentId = contentID;
//To make the image display as inline and not as attachment
inlineLogo.ContentDisposition.Inline = true;
inlineLogo.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
//To embed image in email
msg.Body = "<htm><body> <img src=\"cid:" + contentID + "\"> </body></html>";
編輯:我嘗試了<img width="100" src=\\"cid:" + contentID + "\\">
但是它不起作用,
怎么樣:
msg.Body = "<htm><body> <img width='100px' src=\"cid:" + contentID + "\"> </body></html>";
或符合W3C:
msg.Body = "<htm><body> <img style='width: 100px' src=\"cid:" + contentID + "\"> </body></html>";
您可以在img
標簽上使用width
屬性:
<img width="100" src=\"cid:" + contentID + "\">
但是,某些電子郵件客戶端(例如Outlook 2007和2010)不支持此功能 ,因此,為了使其完全可靠,您需要將包含的圖像調整為正確的尺寸,然后再添加到電子郵件中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.