调整电子邮件中嵌入的图像的大小

时间:2016-12-22 11:53:53

标签: c# asp.net image email

我在电子邮件正文中嵌入了一个图片,但效果很好,但图片尺寸齐全,占用了大部分电子邮件,因此我想调整图片大小。

<div runat="server" id="dvEmailLogo">
   <asp:Image runat="server" ID="EmailLogo" />
</div>

代码背后:

    EmailLogo.ImageUrl = ConfigurationManager.AppSettings["LogoFileFolder"] + Company.Current.CompCode + "\\" + Company.Current.Logo + "";

    Attachment inlineLogo = new Attachment(EmailLogo.ImageUrl);
    mailMsg.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
   mailMsg.Body = "<htm><body> <img src=\"cid:" + contentID + "\"> </body></html>";

我尝试将宽度和高度添加到网址:

EmailLogo.ImageUrl = ConfigurationManager.AppSettings["LogoFileFolder"] + Company.Current.CompCode + "\\" + Company.Current.Logo + @"&width=200&height=200";

但这会导致错误:System.IO.FileNotFoundException:找不到文件

我也尝试将高度加到div dvEmailLogo但是没有改变大小

1 个答案:

答案 0 :(得分:1)

为什么不在html代码上调整图片大小?

mailMsg.Body = "<htm><body> <img height="200" width="200" src=\"cid:" + contentID + "\"> </body></html>";