Reputation: 693
i am using asp.net web forms. i have an file save on on line server. i want to send that file in attachment. i have URL of the file how i attach the file through URL as attachment in email. please guide me.
Thank you
Upvotes: 0
Views: 821
Reputation: 37530
You're going to have to download it before attaching. Try something like this...
var request = (HttpWebRequest)WebRequest.Create(fileUrl);
using (var response = request.GetResponse())
{
using (var responseStream = response.GetResponseStream())
{
var message = new MailMessage("[email protected]", "[email protected]", "subject", "body");
message.Attachments.Add(new Attachment(responseStream, "myfile.pdf"));
var smtpClient = new SmtpClient();
smtpClient.Send(message);
}
}
Upvotes: 2