2015-12-24 7 views
8
string email ="[email protected]"; 
attachment = path + "/" + filename; 
Application.OpenURL ("mailto:" + 
         email+" 
         ?subject=EmailSubject&body=EmailBody"+"&attachment="+attachment); 

उपरोक्त कोड में, attachment काम नहीं कर रहा है। क्या मेलो का उपयोग करके अनुलग्नक जोड़ने का कोई अन्य विकल्प है: सी # में लिंक?सी # में मेलto में अनुलग्नक कैसे जोड़ें?

+1

क्यों नहीं आप System.Net.Mail को एक नज़र लगाव उद्देश्य – csharpcoder

+1

संभव के लिए लगाव वर्ग देना चाहिए, तो आप एक बहुत आसान तरीके से काम प्राप्त कर सकते हैं, यह सभी आवश्यक वर्ग mailaddress तरह लागू किया गया है, और डुप्लिकेट: [सी # मेलटो अटैचमेंट के साथ?] (http://stackoverflow.com/questions/1195111/c-sharp-mailto-with-attachment) –

उत्तर

2

आप System.Net.Mail का उपयोग कर सकते हैं जिसमें MailMessage.Attachments संपत्ति है। की तरह कुछ:

message.Attachments.Add(new Attachment(yourAttachmentPath)); 

या

आप इस तरह की कोशिश कर सकते हैं:

using SendFileTo; 

namespace TestSendTo 
{ 
    public partial class Form1 : Form 
    { 
     private void btnSend_Click(object sender, EventArgs e) 
     { 
      MAPI mapi = new MAPI(); 

      mapi.AddAttachment("c:\\temp\\file1.txt"); 
      mapi.AddAttachment("c:\\temp\\file2.txt"); 
      mapi.AddRecipientTo("[email protected]"); 
      mapi.AddRecipientTo("[email protected]"); 
      mapi.SendMailPopup("testing", "body text"); 

      // Or if you want try and do a direct send without displaying the 
      // mail dialog mapi.SendMailDirect("testing", "body text"); 
     } 
    } 
} 

ऊपर कोड Mapi32.dll उपयोग करता है।

Source

यह शायद दस्तावेज़ संलग्न नहीं होगा क्योंकि आप ईमेल क्लाइंट की स्वतंत्रता पर हैं इन्हें मेल करें प्रोटोकॉल लागू करने और शामिल लगाव खंड के लिए पार्स करने। आपको पता नहीं हो सकता कि पीसी पर मेल क्लाइंट स्थापित है, इसलिए यह हमेशा काम नहीं कर सकता है - आउटलुक निश्चित रूप से मेलto का उपयोग करके अनुलग्नकों का समर्थन नहीं करता है।

+1

"आउटलुक निश्चित रूप से मेलto का उपयोग करके अनुलग्नकों का समर्थन नहीं करता है।" यह कुछ संस्करणों के लिए काम करेगा लेकिन आपका अधिकार, आप नहीं जानते कि मेल क्लाइंट किस प्रकार स्थापित हैं, इसलिए मैं सी # System.Net.Mail.Attachment का उपयोग करने का सुझाव देता हूं। –

+1

@MaxSassen: - उत्तर पोस्ट करने के बाद कारण बताता है, मैंने 'System.Net.Mail' –

2

मेलto: आधिकारिक तौर पर अनुलग्नकों का समर्थन नहीं करता है। मैं Outlook 2003 में सुना है इस वाक्य रचना के साथ काम करेंगे:

<a href='mailto:[email protected]?Subject=SubjTxt&Body=Bod_Txt&Attachment=""C:\file.txt"" '> 

आपकी समस्या पहले से ही उत्तर दिया गया है: c-sharp-mailto-with-attachment

-1

एक बेहतर तरीका यह संभाल करने के लिए का उपयोग कर सर्वर पर मेल भेजने के लिए है System.Net .Mail.Attachment।

public static void CreateMessageWithAttachment(string server) 
{ 
    // Specify the file to be attached and sent. 
    // This example assumes that a file named Data.xls exists in the 
    // current working directory. 
    string file = "data.xls"; 
    // Create a message and set up the recipients. 
    MailMessage message = new MailMessage(
     "[email protected]", 
     "[email protected]", 
     "Quarterly data report.", 
     "See the attached spreadsheet."); 

    // Create the file attachment for this e-mail message. 
    Attachment data = new Attachment(file, MediaTypeNames.Application.Octet); 
    // Add time stamp information for the file. 
    ContentDisposition disposition = data.ContentDisposition; 
    disposition.CreationDate = System.IO.File.GetCreationTime(file); 
    disposition.ModificationDate = System.IO.File.GetLastWriteTime(file); 
    disposition.ReadDate = System.IO.File.GetLastAccessTime(file); 
    // Add the file attachment to this e-mail message. 
    message.Attachments.Add(data); 

    //Send the message. 
    SmtpClient client = new SmtpClient(server); 
    // Add credentials if the SMTP server requires them. 
    client.Credentials = CredentialCache.DefaultNetworkCredentials; 

    try 
    { 
     client.Send(message); 
    } 
    catch (Exception ex) 
    { 
     Console.WriteLine("Exception caught in CreateMessageWithAttachment(): {0}", ex.ToString());    
    } 
    data.Dispose(); 
} 
+2

का उपयोग करने का विकल्प जोड़ा है आपने अभी पोस्ट की प्रतिलिपि बनाई है: http://stackoverflow.com/questions/1195111/c-sharp-mailto साथ-साथ संलग्नक # उत्तर -1195153 बस उससे लिंक करें –

संबंधित मुद्दे