문제

And i am sending mails from below details :

// language -- C#
// import namespace
using System.Web.Mail;

private void SendEmail()
{
   const string SERVER = "relay-hosting.secureserver.net";
   MailMessage oMail = new System.Web.Mail.MailMessage();
   oMail.From = "emailaddress@domainname";
   oMail.To = "emailaddress@domainname";
   oMail.Subject = "Test email subject";
   oMail.BodyFormat = MailFormat.Html;  // enumeration
   oMail.Priority = MailPriority.High;  // enumeration
   oMail.Body = "Sent at: " + DateTime.Now;
   SmtpMail.SmtpServer = SERVER;
   SmtpMail.Send(oMail); 
   oMail = null;    // free up resources

}

Mails are going properly with above details and now i want to add attachment on email.And for that i have added below code :

String sFile = "http://www.demo.com/abc.pdf";
var oAttch = new System.Web.Mail.MailAttachment(sFile);

oMail.Attachments.Add(oAttch);

But it's not adding the attachment in mail.

It's giving error that "URI formats are not supported".

도움이 되었습니까?

해결책

Mail attachment supports only files from the local drive.

If you want to attach a file that is hosted on the web you should download it to your local drive first.

If you have the file in your local drive you can do something like this:

String sFile = "abc.pdf";
var oAttch = new System.Web.Mail.MailAttachment(Server.MapPath(sFile));

oMail.Attachments.Add(oAttch);

다른 팁

You cant use a file from the web. It must be located on your local drive.

Check out MSDN - MailAttachment Constructor (String)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top