Send an email with the application from the WinForms application?

I am currently using Process.Start to send simple emails from my WinForms application. Can you come up with some way to add a file attachment to an email? (Edit: using Process.Start?)

Here is what I am using now:

Process.Start("mailto:test@test.invalid?subject=" + HttpUtility.HtmlAttributeEncode("Application error report") + "&body=" + body);
+3
source share
1 answer

Try something like this →

MailMessage theMailMessage = new MailMessage("from@email.com", "to@email.com");
theMailMessage.Body = "body email message here";
theMailMessage.Attachments.Add(new Attachment("pathToEmailAttachment"));
theMailMessage.Subject = "Subject here";

SmtpClient theClient = new SmtpClient("IP.Address.Of.Smtp");
theClient.UseDefaultCredentials = false;
System.Net.NetworkCredential theCredential = new System.Net.NetworkCredential("user@name.com", "password");
theClient.Credentials = theCredential;
theClient.Send(theMailMessage);

Well, based on your edit and additional information, I found this blog post by Jon Galloway , "Sending files via the default mail client . "

, , , , .

, .

+6

Source: https://habr.com/ru/post/1731490/


All Articles