.net - attaching file with email from some other server (URL) ? pleaes guide -


In an asp.net page I am sending emails with attachments to have the problem files stored on another server. Please try to give the URL to the file, but error "URI formats are not supported."

  Message. Add (new attachment ("http: // domain .com / upload / cv.doc"));   

Please direct me how to attach files to other servers.

First, load the file inside the c # / asp.net code by using HttpWebRequest Read the results by using the StreamReader , save it to a local file (which is the right on the file system that is in your ASP.Net app). Then specify the filename of the newly created file.

Do not forget to delete the local file when the email is already sent.

Edit :

It should work directly with the file path if the file is under the same website, then try using it:

  var filePath = HttpContext.Current.Server.MapPath ("/ someTempFile.dat"); // here / - The website is root. // Now use FilePath as an argument for attachment () constructor   

The same is true if this file is where you downloaded the file from another domain.

If the file is not under the website, then you should be good by using paths like

  var filePath = "C: \ SomeTempFolder \ someTempFile.dat";   

I hope it helps!

Comments