C # MailTo z załącznikiem?

Obecnie używam poniższej metody, aby otworzyć konto e-mail outlook użytkowników i wypełnić e-mail z odpowiednią treścią do wysłania:

public void SendSupportEmail(string emailAddress, string subject, string body)
{
   Process.Start("mailto:" + emailAddress + "?subject=" + subject + "&body=" 
                + body);
}

Chcę jednak móc wypełnić e-mail załączonym plikiem.

Coś w stylu:

public void SendSupportEmail(string emailAddress, string subject, string body)
{
   Process.Start("mailto:" + emailAddress + "?subject=" + subject + "&body=" 
      + body + "&Attach="
      + @"C:\Documents and Settings\Administrator\Desktop\stuff.txt");
}

Jednak to nie wydaje się działać. Czy ktoś zna sposób, który pozwoli to zadziałać!?

/ Align = "left" / Pozdrawiam.
Author: Dave Cousineau, 2009-07-28

5 answers

Mailto: nie obsługuje oficjalnie załączników. Słyszałem, że Outlook 2003 będzie działał z tą składnią:

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

Lepszym sposobem jest wysłanie poczty na serwer za pomocą 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();
    }
 10
Author: Jon Galloway,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-04-15 17:52:29

Jeśli chcesz uzyskać dostęp do domyślnego klienta poczty e-mail, możesz użyć MAPI32.dll (działa tylko w systemie operacyjnym Windows). Spójrz na następujący wrapper:

Http://www.codeproject.com/KB/IP/SendFileToNET.aspx

Kod wygląda tak:

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");
 50
Author: Alex,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-08-29 20:14:10

Czy ta aplikacja naprawdę musi używać Outlooka? Czy istnieje powód, dla którego nie używasz przestrzeni nazw System. Net. Mail?

Jeśli naprawdę potrzebujesz korzystać z Outlooka (i nie polecam go, ponieważ wtedy bazujesz swoją aplikację na zależnościach innych firm, które mogą się zmienić), będziesz musiał zajrzeć do Microsoftu.Przestrzenie nazw biur

Zacząłbym tutaj: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.aspx

 4
Author: David,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-07-28 16:09:28

Spróbuj tego

var proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = string.Format("\"{0}\"", Process.GetProcessesByName("OUTLOOK")[0].Modules[0].FileName);
proc.StartInfo.Arguments = string.Format(" /c ipm.note /m {0} /a \"{1}\"", "[email protected]", @"c:\attachments\file.txt");
proc.Start();
 2
Author: kernowcode,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-08-27 13:22:34

Oficjalnie tak protokół mailTo nie obsługuje załączników. Ale Williwyg wyjaśnił to bardzo dobrze tutaj, że jest sposób, aby to zrobić - Otwórz domyślnego klienta poczty wraz z załącznikiem

 0
Author: Mahesh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:09:45