简体   繁体   English

通过电子邮件发送带有图像的html文件

[英]Sending html file with images via email

How can i send html mail with images in c#? 如何在c#中发送包含图像的html邮件? Can i just set direct link to image on my server(something like <img src="http://mysite.ru/img.png" /> ) or i need attache image and then use link to my attached file? 我可以在我的服务器上设置直接链接到图像(类似于<img src="http://mysite.ru/img.png" /> ),或者我需要附带图像,然后使用链接到我的附件? Is there any examples or ready to use libraries? 是否有任何示例或准备使用库? What about css files and scripts? 那些css文件和脚本呢?

There are multiple methods of coding in-line images. 有多种编码在线图像的方法。 We use VB.NET in house and this site is an excellent reference http://www.systemnetmail.com/default.aspx 我们在内部使用VB.NET,这个网站是一个很好的参考http://www.systemnetmail.com/default.aspx

If you directly embed the links into the email (pointing to an external server) you'll get blocked by most clients, but the user can turn them on. 如果您直接将链接嵌入到电子邮件中(指向外部服务器),您将被大多数客户端阻止,但用户可以将其打开。

They can be embedded in the usual manner of: 它们可以通常的方式嵌入:

<img src="http://go.com/go.gif" />

If you need it to show up by default you'll need to embed the image as an attachment and link to that attachement inline. 如果您需要在默认情况下显示它,则需要将图像作为附件嵌入并链接到该内联的附件。

See: http://www.systemnetmail.com/faq/2.6.aspx 请参阅: http//www.systemnetmail.com/faq/2.6.aspx

For CSS it is common to use inline style and no referenced files the images on the other side should be just links and not send with the email. 对于CSS,通常使用内联样式而不引用文件,另一侧的图像应该只是链接而不是随电子邮件发送。 You just need to declare the mail content as html and you are ready to go. 您只需要将邮件内容声明为html即可开始使用。 JavaScript is also available I use it fir some repositioning. JavaScript也可用我用它来重新定位。

See http://en.wikipedia.org/wiki/MHTML : http://en.wikipedia.org/wiki/MHTML

MHTML, short for MIME HTML, is a web page archive format used to combine resources that are typically represented by external links (such as images, Flash animations, Java applets, audio files) together with HTML code into a single file. MHTML是MIME HTML的缩写,是一种网页存档格式,用于将通常由外部链接(如图像,Flash动画,Java小程序,音频文件)和HTML代码表示的资源组合到一个文件中。 The content of an MHTML file is encoded as if it were an HTML e-mail message, using the MIME type multipart/related. 使用MIME类型multipart / related对MHTML文件的内容进行编码,就像它是HTML电子邮件一样。 The first part of the file is normally encoded HTML; 该文件的第一部分通常是编码HTML; subsequent parts are additional resources identified by their original URLs and encoded in base64. 后续部分是由其原始URL标识并在base64中编码的其他资源。 This format is sometimes referred to as MHT, after the suffix .mht given to such files by default when created by Microsoft Word, Internet Explorer, or Opera. 在Microsoft Word,Internet Explorer或Opera创建的默认情况下,此格式有时称为MHT,后缀为.mht。 MHTML is a proposed standard, circulated in a revised edition in 1999 as RFC 2557. MHTML是一个提议的标准,于1999年作为RFC 2557在修订版中发布。

Learning more about MHTML may be the key to solving the problem. 更多地了解MHTML可能是解决问题的关键。

probably the best option is to use some package like MvcMailer. 可能最好的选择是使用像MvcMailer这样的包。

Mvc Mailer display the following characteristics: Mvc Mailer显示以下特征:

MvcMailer sends emails using the MVC views as Email Body with no effort. MvcMailer毫不费力地使用MVC视图作为电子邮件正文发送电子邮件。 Here's a quick list of features: 这是一个快速的功能列表:

a) Use Razor/WebForms views a)使用Razor / WebForms视图

b) Use Master pages b)使用母版页

c) Write Testable Code c)编写可测试代码

d) Pass values to your view using ViewBag or ViewModel and d)使用ViewBag或ViewModel和值将值传递给视图

e) Generate Absolute URL using Url.Abs method and e)使用Url.Abs方法生成绝对URL

f) create multi-part emails by just adding a view file, f)只需添加一个视图文件即可创建多部分电子邮件,

g) scaffold your mailers. g)绞刑你的邮件。 MvcMailer has a MailerBase class that extends ControllerBase class. MvcMailer有一个扩展ControllerBase类的MailerBase类。

So, Mailers are just like your Controllers. 因此,Mailers就像你的控制器一样。 As a result, you can use all the controller goodies without any learning curve, period. 因此,您可以使用所有控制器好东西而无需任何学习曲线,周期。 The end result is a professional looking HTML email body ready for your to send to your website users. 最终结果是一个专业的HTML电子邮件正文,可以发送给您的网站用户。

Visit the Project site for a comprehensive tutorial on MvcMailer. 访问项目网站,获取有关MvcMailer的综合教程。 https://github.com/smsohan/MvcMailer/wiki/MvcMailer-Step-by-Step-Guide https://github.com/smsohan/MvcMailer/wiki/MvcMailer-Step-by-Step-Guide

On the step guid you will find how you can send emails using images. 在步骤guid上,您将找到如何使用图像发送电子邮件。

brgds. brgds。 sebastian. 塞巴斯蒂安。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM