2016-12-22 53 views
1

我在电子邮件的正文中嵌入图像,并且工作正常,但图像是全尺寸的,占用了大部分电子邮件,所以我想调整图像大小。调整嵌入到电子邮件中的图像的大小

<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但是没有cha nge的大小

+0

您可以使用CSS伸展在DIV http://stackoverflow.com/questions/1891857/how-do-you-stretch-an-image-to-fill-a-div-while-keeping图像-the-images-aspect-rat –

+1

@Alexey CSS不适用于许多电子邮件客户端。 OP使用'Path.Combine'来制定路径并解决* FileNotFound *使用工具:Process Monitor。这将显示文件试图找到的位置,以便您可以看到必须更改的内容。 –

+0

您可以在html''中设置图片的宽度。那是在磁盘上找到图像之后。 – VDWWD

回答

1

为什么不调整图像的html代码?

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