Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2288
  • Last Modified:

HTML & Powershell - HTML Mail body, how to create a link from body to attachment (xlsx) in the same email

Hello,

Please advice,

I created a mail body in html, and I woul like to link a link to the attachment which is included in the email. I would like to click the link in the HTML body of email and it woul automatically open the attached attachement. Would this be possible? I tried to google, but not much results. I am using Powershell to send email, and include attachments.

Many thanks

 
<body >
 <h2> Key: </h2>
 <table>
 <tr>
 <td>   
 <ol  >
 <li> <span><a href="default2.aspx" >SubcontractorsExport1.csv</a> -- Export of subcontractors without the direct manager or accountexpires. </span></li>  
 <li> <span>SubcontractorsExport2.csv -- Export of subcontractors whose account expires later than in 4 months. </span></li> 
 </ol> 
 </td>
 </tr>
 </table>
 </body>

Open in new window


0
Radim88
Asked:
Radim88
  • 2
  • 2
1 Solution
 
kivan24Commented:
Add this code to your html mail body.
Attached file name and name in the href attribute must be identical
<a href="attached_file_name.xlsx">open attached file</a>

Open in new window

0
 
Radim88Author Commented:
Hi,
Sorry this doesnt work, It opens browser with empty page.
Thx,
0
 
kivan24Commented:
Work for me.

Look here:
The solution is below, however, this only works for a single attachment. When there are multiple attachments my email client only wants to open the first one attached regardless of the fact that each file link has a unique content id... Uncertain of "why" this happens at this point but the main objective is resolved.

MailMessage msg = new MailMessage("you@email.com", "you@email.com");
msg.Subject = "Test";
Attachment atch = new Attachment("c:\\SomeTestDoc.pdf");
atch.ContentId = Guid.NewGuid().ToString();
msg.Attachments.Add(atch);
msg.IsBodyHtml = true;
msg.Body = string.Format("This is my <a href=cid:{0}>file</a>", atch.ContentId);

SmtpClient client = new SmtpClient("localhost", 25);
client.Send(msg);
0
 
Radim88Author Commented:
thx it really works:)

<a href=cid:subcontractorsExport3.csv>file</a>subcontractorsExport3.csv</a>
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now