将HTML格式的电子邮件中的链接设置为打开附件 [英] Setting Link in HTML-formatted Email to Open Attachment

查看:346
本文介绍了将HTML格式的电子邮件中的链接设置为打开附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,是否可以在html格式的电子邮件正文中设置链接,单击该链接时将在同一封电子邮件中打开文件附件?

其次,如果可能,那么如何才能完成?


解决方案

我必须感谢同志解决这个问题。我猜有些时候你真的不需要远行去寻找有解决方案的人。

所以下面概述了解决方案,但请注意,当附加多个文档时仍然存在问题,即使创建的链接同时具有唯一ID,我的邮件客户端也只想加载第一个文档和文件名。


MailMessage msg = new MailMessage(" you@youremail.com "," you@youremail.com ");


msg.Subject =" Test";


附件atch = new Attachment(" c: \\SomeTestFile.docx");


atch.ContentId = Guid.NewGuid()。ToString();


msg.Attachments.Add(atch);


< span style ="font-size:11pt; color:#1f497d; font-family:'Calibri','sans-serif'"> msg.IsBodyHtml = true;


msg.Body ="这是我的< a href = \" cid:" originalAttribute = QUOT; HREF" originalPath = QUOT; \" CID:"" originalAttribute = QUOT; HREF" originalPath = QUOT; \" CID:"" + atch.ContentId +" \"> file< / a>" ;;



SmtpClient client = new SmtpClient(" localhost",25);
client.Send(msg);


First, is it possible to set a link in an html-formatted emails body that when clicked will open a file attachment on the same email?

Second, if possible then how can this be done?


解决方案

I must thank a fellow comrade for the solution to this.  I guess some times you really don't need to travel far to find someone with a solution. 

So below outlines the solution to this but note that there still is an issue when multiple documents are attached where my mail client only wants to load up the first document attached even though the link being created has both a unique id and file name.

MailMessage msg = new MailMessage("you@youremail.com", "you@youremail.com");

            msg.Subject = "Test";

            Attachment atch = new Attachment("c:\\SomeTestFile.docx");

            atch.ContentId = Guid.NewGuid().ToString();

            msg.Attachments.Add(atch);

            msg.IsBodyHtml = true;

            msg.Body = "This is my <a href=\"cid:" originalAttribute="href" originalPath="\"cid:"" originalAttribute="href" originalPath="\"cid:"" + atch.ContentId + "\">file</a>";

 

            SmtpClient client = new SmtpClient("localhost", 25);
            client.Send(msg);


这篇关于将HTML格式的电子邮件中的链接设置为打开附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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