One Mailto string with attachment syntax needed?

I need to use one string like this, but cannot get the attachment to show when the email app (Outlook) opens up.

    string filename = "mailto:me@mycompany.com?subject=Support%20File%20Sending?&body=Please%20attach%20support%20file.&cc=%20&bcc=%20&Attach=C:\Program%20Files\MyCompany\MyProgram\Logs\support.txt";
LVL 1
kvnsdrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ThejakaCommented:
You may need to enclose the file path in double quotes. Even this method may not work with all email clients or on all operating systems.
0
Éric MoreauSenior .Net ConsultantCommented:
there is no official supports for the attachment on the mailto command line. it sometimes works on some PC and not on others. better find another way
0
JimBrandleyCommented:
You can send email fairly easily using MailMessage and SmtpClient.

Jim

public void SendMessage( string recipient, string sender, string ccRecipients,
                         string subject, string bodyText, MailPriority priority,
                         string attachmentPath, string smtpServer, int smptpPort,
                         bool credentialsRequired, bool useSSL, string userName,
                         string passWord, ref string error)
{
   string   from;
   string   ccTo;
 
   ccTo = ccRecipients.Trim();
 
   from = sender;
 
   if (recipient.Length == 0)
   {
      error = "Cannot send email. Recipient address is empty.";
      return;
   }
   if (bodyText.Length == 0)
   {
      error = "Cannot send email. Message is empty.";
      return;
   }
 
   MailMessage eMail = GetMailMessage(from, recipient, ccTo);
   eMail.Subject = subject;
   eMail.Body = bodyText;
   eMail.Priority = priority;
 
   // Check for an attachment
   Attachment attachment = CreateAttachment(attachmentPath);
   if (attachment != null)
      eMail.Attachments.Add(attachment);
 
   if (smtpServer.Length > 0)
   {
      //Send the message.
      try
      {
         SmtpClient client = new SmtpClient(smtpServer, smptpPort);
 
         // Now add credentials as required
         if (credentialsRequired)
         {
            if (useSSL)
            {
               client.UseDefaultCredentials = false;
               client.EnableSsl = true;
            }
            else
            {
               client.UseDefaultCredentials = true;
               client.EnableSsl = false;
            }
            NetworkCredential cred = new NetworkCredential(userName, passWord);
            client.Credentials = cred;
         }
         client.Send(eMail);
         eMail.Dispose();
      }
      catch (SmtpFailedRecipientException e)
      {
         string badAddress = e.FailedRecipient;
         error = "SMTP server reported the following addresses as undeliverable: " + badAddress;
      }
   }
   else
   {
      error = "Cannot send email. SMTP Server not specified by caller.";
   }
}
private Attachment CreateAttachment(string path)
{
   if (path.Length == 0)
      return null;
 
   // See if we have an attachment:
   FileInfo info = new FileInfo(path);
   if (info.Exists) // There's one there
   {
      if (info.Length > 0) // Send it
      {
         Attachment attachment = new Attachment(path);
         return attachment;
      }
   }
   return null;
}
/// <summary>
/// The MailMessage constructor is unhappy with semicolon-delimited lists of addresses,
/// so this breaks them up.
/// </summary>
/// <param name="sender"></param>
/// <param name="recipient"></param>
/// <param name="ccRecipients"></param>
/// <returns></returns>
private MailMessage GetMailMessage(string sender, string recipient, string ccRecipients)
{
   bool singleRecipient = ( recipient.IndexOf(';') == -1 );
   bool singleCCRecipient = ( ccRecipients.IndexOf(';') == -1 );
 
 
   MailMessage message = new MailMessage();
   if (singleRecipient)
   {
      message.To.Add(recipient);
   }
   else // Need to break the recipient list up.
   {
      string[] recipients = recipient.Split(';');
      for (int index = 0; index < recipients.Length; index++)
      {
         if (recipients[index].Trim().Length > 0)
            message.To.Add(recipients[index].Trim());
      }
   }
 
   if (!singleCCRecipient) // Need to break the CC recipient list up.
   {
      string[] recipients = ccRecipients.Split(';');
      for (int index = 0; index < recipients.Length; index++)
      {
         if (recipients[index].Trim().Length > 0)
            message.CC.Add(recipients[index].Trim());
      }
   }
   else if (ccRecipients.Length > 0)   // Single CC
   {
      message.CC.Add(ccRecipients);
   }
 
   // Finally, add the sender
   message.From = new MailAddress(sender.Trim());
   return message;
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.