Pregunta

Actualmente estoy usando el método de abajo para abrir la cuenta de correo electrónico de Outlook usuarios y poblar un correo electrónico con el contenido relevante para el envío:

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

Quiero sin embargo, ser capaz de poblar el correo electrónico con un archivo adjunto.

algo como:

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");
}

Sin embargo, esto no parece funcionar. ¿Alguien sabe de una manera que permita que esto funcione!?

Ayuda apreciar en gran medida.

Saludos.

¿Fue útil?

Solución

mailto: no es compatible oficialmente adjuntos. He oído Outlook 2003 puede trabajar con esta sintaxis:

<a href='mailto:name@domain.com?Subject=SubjTxt&Body=Bod_Txt&Attachment=""C:\file.txt"" '>

Una mejor manera de manejar esto es para enviar el correo en el servidor usando 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(
           "jane@contoso.com",
           "ben@contoso.com",
           "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();
    }

Otros consejos

Si desea acceder al cliente de correo electrónico predeterminado, puede utilizar MAPI32.dll (funciona en el sistema operativo Windows solamente). Echar un vistazo a la siguiente envoltorio:

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

código es el siguiente:

MAPI mapi = new MAPI();
mapi.AddAttachment("c:\\temp\\file1.txt");
mapi.AddAttachment("c:\\temp\\file2.txt");
mapi.AddRecipientTo("person1@somewhere.com");
mapi.AddRecipientTo("person2@somewhere.com");
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");

¿Esta aplicación realmente necesita para utilizar Outlook? ¿Hay alguna razón para no usar el espacio de nombres System.Net.Mail?

Si realmente es necesario utilizar Outlook (y yo no lo recomendaría porque entonces usted está basando su aplicación en las dependencias de 3 ª parte que es probable que cambie) tendrá que buscar en los espacios de nombres Microsoft.Office

Yo empezaría aquí: http://msdn.microsoft.com/en- es / library / microsoft.office.interop.outlook.aspx

Probar

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}\"", "someone@somewhere.com", @"c:\attachments\file.txt");
proc.Start();

Oficialmente sí el protocolo mailTo no es compatible con los archivos adjuntos. Pero Williwyg lo explicó muy bien aquí que hay una manera de hacerlo - abierto junto con un archivo adjunto

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top