0

I'm trying to launch the email app from the user click some hyper link, I want to add also attachment, the only thing that worked was this link enter link description here, but now I don't want to specify the MailMessage.From field, I want it to be like when you click on mailto: link, it opens your deafault account or ask you to login, etc.., but whenever I try to set the mailMessage.From = new MailAddress("");, it throws exception, it should be an email

to get my app launch the mail with attachment, now how can I remove the field "From" and let the user use his mail or something like when you use mailto: if I remove this line, it throws exception

mailMessage.From = new MailAddress();

1 Answers1

0

If you want your WPF application to send an e-mail directly you should use the SmtpClient Class MSDN.

If you are trying to launch the default mail app (like outlook) to send the e-mail, I'd use Process.Start as one of the answers to the question linked specified.

var url = "mailto:user@domain.com";
// var url = "mailto:?subject=aSubject&body=aBody";
// var url = "mailto:?subject=aSubject&body=aBody&attachment=aFile";
Process.Start(url);
codebender
  • 469
  • 1
  • 6
  • 23
  • I'm trying to launch, but if I try to use this one // var url = "mailto:?subject=aSubject&body=aBody&attachment=aFile"; the file is never attached – Ahmed Abdo Ortiga Apr 12 '18 at 23:40
  • 1
    attachment is only supported by a few e-mail clients. I suggest you use the SmtpClient Class, it has full support for attachments. https://msdn.microsoft.com/en-us/library/system.net.mail.attachment(v=vs.110).aspx – codebender Apr 13 '18 at 01:22