将图像嵌入HTML文本中以用于电子邮件 [英] Embedding images in HTML text for email purposes

查看:103
本文介绍了将图像嵌入HTML文本中以用于电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个程序可以将电子邮件作为带有嵌入式图像的HTML发送.图像是消息的徽标.但是,程序需要知道图像文件的名称才能执行此操作.我希望能够在文件中找到该名称并将其用作嵌入的基础.另外,无论文件包含多少,我都希望将所有图像引用转换为嵌入式图像. HTML参考可以是:

src ="Images/QMLogo%2025%20pct.jpg"

在这种情况下,我想执行以下操作:

替换(HTMLText,"src = *.jpg","src = CID:companylogo"),结果为

src = CID:companylogo

同时,我需要将图像文件路径存储在字符串变量中,以便可以将其用作对CID的实际图像文件的引用.

由于CID实际上是任意的,因此它可以是"pic1"而不是"companylogo".如果HTML文本包含五个图像文件引用,则我想对每个引用进行不同的处理.换句话说,第一个图像文件引用将变为"src = CID:pic1",第二个图像文件引用将变为"src = CID:pic2",依此类推.

总而言之,我希望能够在富文本框中使用HTML文本,将所有图像文件引用转换为电子邮件中的嵌入式图像,通过电子邮件发送结果,并将所有图像显示在收件人电子邮件地址上-而无需知道图像文件名.理想情况下,它是通过将HTML文本作为by ref参数的过程来执行的.我相信我将不得不使用RegEx,但是我是新手,并且还没有找到任何能做到这一点的示例代码.在我看来,这在实用程序中将是一个方便的过程.有任何想法吗?我正在使用VB .NET2010.

谢谢,

Mike

Hi,

I have a program that sends email as HTML with an embedded image. The image is a logo for the message. However, the program needs to know the name of the image file to do it. I''d like to be able to find the name in the file and use that to be the basis for the embedding. In addition, I''d like to convert all the image references to an embedded image no matter how many the file contains. The HTML reference could be:

src="Images/QMLogo%2025%20pct.jpg"

In this case I want do something like the following:

Replace(HTMLText, "src=*.jpg", "src=CID:companylogo") and have the result be

src=CID:companylogo

At the same time I need to store the image file path in a string variable so that it could be used as a reference to the actual image file for the CID.

Since the CID is actually arbitrary, it could be "pic1" instead of "companylogo". If the HTML text contains five image file references, I want to manipulate each one differently. In other words, the first image file reference would become "src=CID:pic1", the second image file reference would become "src=CID:pic2", and so on.

To summarize, I want to be able to take the HTML text within a rich text box, convert all image file references to embedded images within an email message, email the result, and have all the images appear at the recipient email address - without having to know the image file names. Ideally, it would be performed by a procedure with the HTML text as a by ref parameter. I believe I''ll have to use RegEx but I''m new to it and haven''t found any sample code that does this. It seems to me that this would be a handy procedure to have within a utility. Any ideas? I''m using VB .NET 2010.

Thanks,

Mike

推荐答案

查看有关如何创建带有嵌入式图像的多部分电子邮件的第一个链接.第二个链接的方法有些不同,看起来不错且很简单,但尚不支持.

http://www.htmlcodetutorial.com/help/ftopic5309.html [ http://www.campaignmonitor.com/blog/post/1761/embedding-images -in-email/ [ ^ ]

祝你好运!
Check out the first link on how to create a multipart email message with embedded images. The second link has a somewhat different approach which look nice and simple but isn''t supported (yet).

http://www.htmlcodetutorial.com/help/ftopic5309.html[^]

http://www.campaignmonitor.com/blog/post/1761/embedding-images-in-email/[^]

Good luck!


这篇关于将图像嵌入HTML文本中以用于电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆