发送电​​子邮件与附件的WinForms应用程序? [英] Send email with attachment from WinForms app?

查看:172
本文介绍了发送电​​子邮件与附件的WinForms应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用的Process.Start我从我的WinForms应用程序发送简单的电子邮件。你能想到的任何方式来添加文件附件的电子邮件? (编辑:使用的Process.Start)

下面是我现在用的是什么:

 的Process.Start(电子邮件地址:test@test.invalid主题=+ HttpUtility.HtmlAttributeEn code(应用程序错误报告)+&放大器;身体= +体);
 

解决方案

尝试是这样的 - >

  MailMessage theMailMessage =新MailMessage(from@email.com,to@email.com);
theMailMessage.Body =身体的电子邮件在这里;
theMailMessage.Attachments.Add(新的附件(pathToEmailAttachment));
theMailMessage.Subject =主题这里;

SmtpClient theClient =新SmtpClient(IP.Address.Of.Smtp);
theClient.UseDefaultCredentials = FALSE;
System.Net.NetworkCredential theCredential =新System.Net.NetworkCredential(user@name.com,密码);
theClient.Credentials = theCredential;
theClient.Send(theMailMessage);
 


好了,根据你的编辑和其他信息,我发现这个博客由乔恩·加洛韦后,<一个href="http://weblogs.asp.net/jgalloway/archive/2007/02/24/sending-files-via-the-default-e-mail-client.aspx"相对=nofollow> 发送通过默认的电子邮件客户端文件。

这看起来像你可能会找什么,虽然我不信奉用这种方式的任何知识,我一直用我张贴的方法。

希望这是利用你。

I am currently using Process.Start to send simple emails from my WinForms app. Can you think of any way to add a file attachment to the email? (Edit: using Process.Start?)

Here's what I use now:

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

解决方案

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


Alright, based on your edit and additional info, I found this Blog Post by Jon Galloway, "Sending files via the default e-mail client".

This looks like what you may be looking for, though I don't profess any knowledge with this way as I have always used the method I posted.

Hopefully it is of use to you.

这篇关于发送电​​子邮件与附件的WinForms应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆