Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, How to attach a file(from external source) to an email.

I have a email function in C# and trying to send an attachment. If the attachment is within the project then its working. But if I upload/move the attachment to out of the project/application folder its gives error

"System.IO.IOException: The filename, directory name, or volume label syntax is incorrect. :


How do i solve it ?

What I have tried:

MimeMessage messageClient = new MimeMessage();
messageClient.From.Add(new MailboxAddress("From Name", _config.GetSection("EmailUsername").Value));
messageClient.To.Add(MailboxAddress.Parse(ClientEmail));
messageClient.Subject = CleintSubject;
BodyBuilder bodyBuilder = new BodyBuilder();
bodyBuilder.HtmlBody = ClinetMailBody;

bodyBuilder.Attachments.Add(_env.WebRootPath + "\\downloads\\sample.pdf"); ==> Working

bodyBuilder.Attachments.Add(@"https://abc.com/assets/sample.pdf"); ==> Not working

Any thoughts ?
Posted
Updated 23-Mar-23 3:30am
v2

1 solution

You can't attach a file that is on a different PC via an internet URL: it has to be physically located on a computer the email server can get to.

Why not download it, and then attach the file? You can always have a monthly, weekly, or daily "clean up" process to get rid of them.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900