1

is there a possibility to attach a file in an email, and put it as a link inside the body of mail?

// email body
string emailText = "Attachment file is: <a href="???">Here</a>";

//mail message
MailMessage mailMessage = new MailMessage
{
   From = new MailAddress("from", "from"),
   Subject = "Subject",
   IsBodyHtml = true,
   Body = emailText
};

// here is my attachment
Attachment attachment = new Attachment(object, MediaTypeNames.Application.Pdf);
mailMessage.Attachments.Add(attachment)

is there a solution to include attachment inside the body as a link?

Nouh Belahcen
  • 774
  • 1
  • 11
  • 36
  • This doesn't appear to be possible to do with emails generally: https://stackoverflow.com/q/6146171/120955. The specifics about using C# to do it are irrelevant. – StriplingWarrior Jun 17 '20 at 20:33
  • Images included in an HTML email are usually attached and referenced as CID URI not URL. You may need to do your own MIME! Sending the file in the email base 64 makes email bigger by 4/3 the file size, so also consider using a URL to a web server, your own or an often free public one like Google Drive. While such a file will generally be publicly accessible, email is mostly un-encrypted, so each has a problematic security model. https://stackoverflow.com/questions/6146171/html-code-link-within-an-email-to-an-email-attachment – David G. Pickett Jun 17 '20 at 21:02
  • really thanks I found your answer really helpful I use another way is to upload the file in the server and I put the put in the email. – Nouh Belahcen Jun 20 '20 at 23:48

0 Answers0