मैं अपनी ashx
फ़ाइल में अनुलग्नक के रूप में एक अपलोड की गई फ़ाइल को भेजने की कोशिश कर रहा हूं। यहां मैं जिस कोड का उपयोग कर रहा हूं वह है:अनुलग्नक के रूप में अपलोड की गई फ़ाइल भेजें
HttpPostedFile fileupload = context.Request.Files[0];
//filename w/o the path
string file = Path.GetFileName(fileupload.FileName);
MailMessage message = new MailMessage();
//*****useless stuff********
message.To.Add("[email protected]");
message.Subject = "test";
message.From = new MailAddress("[email protected]");
message.IsBodyHtml = true;
message.Body = "testing";
//*****useless stuff********
//Fault line
message.Attachments.Add(new Attachment(file, MediaTypeNames.Application.Octet))
//Send mail
SmtpClient smtp = new System.Net.Mail.SmtpClient("xxxx", 25);
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("xxx", "xxxx");
smtp.Send(message);
मैं संलग्नक के बिना ईमेल भेजने में सक्षम हूं। क्या मुझे पहले फ़ाइल को सहेजने की आवश्यकता है और फिर अटैचमेंट में जोड़ें?
आपको पहले फ़ाइल को सहेजने की आवश्यकता है; यहां एक मेल संदेश में एक छवि संलग्न करने के समान प्रश्न देखें: http://stackoverflow.com/questions/6105904/how-to-send-image-as-attachement-without-saving-it-in-file-system – dash
हाँ बात मिल गई। मैं Server.MapPath() का उपयोग नहीं कर सका। समाधान HttpContext.Current.Server.MapPath() है। – nikhil