In an Asp.net page I am sending emails with attachments. Issue is the files to attach are stored on some other server. Please guide how to attach such a file. I tried to give URL of file but got error "URI formats are not supported."
Message.Attachments.Add(new Attachment("http://domain.com/upload/cv.doc"));
Please guide me how to attach file from ot开发者_StackOverflow社区her server.
First load the file using HttpWebRequest
inside C#/Asp.Net code, read the result using StreamReader
, save it to the local file (provided your Asp.Net app has such rights on the file system). Then specify the file name of newly created file.
Don't forget to delete the local file when email is already sent.
EDIT:
It should work with a straight file path. If the file is under the same website, then try using this:
var filePath = HttpContext.Current.Server.MapPath("/someTempFile.dat"); // here / - is the website root.
//now use filePath as an argument to Attachment() constructor.
The same is true if this is the file where you downloaded the file from other domain.
If the file is located not under the website, then you should be good by using path like
var filePath = "C:\SomeTempFolder\someTempFile.dat";
I hope this helps!
精彩评论