通过基于C#桌面的应用程序发送电子邮件 [英] sending emails through c# desktop based application

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

问题描述

当我在c#内置的窗口应用程序中单击按钮时,我想将邮件发送到文本框中列出的各个人:omg:

i want to send mail to various pepole listed in a textbox, when a button gets clicked in window application built in c# :omg:

推荐答案

protected void sendEmail(string address, string subject, string from, string body)
    {
        System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
        message.To.Add(address);
        message.Subject = subject;
        message.From = new System.Net.Mail.MailAddress(from);
        message.Body = body;
        System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
        smtp.Credentials = new System.Net.NetworkCredential("host", "password");
        smtp.Port = 587;
        smtp.Send(message);
    
    }


在CodeProject上有几篇文章向您展示了如何以编程方式发送电子邮件.您要问的其余内容就是将列表框设置为多选ListBox,然后遍历ListBox.SelectedItems集合以获取名称(或电子邮件地址或项目,无论如何).
There are several articles on CodeProject that show you how to send email programatically. The rest of what you''re asking is simply setting the listbox as a multi-select ListBox and iterating through the ListBox.SelectedItems collection to get the names (or email addresses, or items, whatever).


我听不懂
< pre lang ="xml">//创建电子邮件
System.Net.Mail.MailMessage邮件=新的MailMessage();
mail.To =& quot; to@there.com& quot ;;
mail.From =& quot; from@here.com& quot ;;
mail.Subject =&"subject&";
mail.Body =&身体&";
& lt; strike& gt;//发送电子邮件
SmtpMail.SmtpServer =&您的smtp服务器详细信息&";
SmtpMail.Send(mail);</strike& gt;
//清理上面的那一部分,您应该改用system.net.mail.
//发送电子邮件.
SmtpClient客户端=新的SmtpClient(&您的smtp服务器地址&",端口号);
client.Send(mail);</pre>
i don''t understand
<pre lang="xml">// Create the email
System.Net.Mail.MailMessage mail = new MailMessage();
mail.To = &quot;to@there.com&quot;;
mail.From = &quot;from@here.com&quot;;
mail.Subject = &quot;subject&quot;;
mail.Body = &quot;the body&quot;;
&lt;strike&gt;// Send the email
SmtpMail.SmtpServer = &quot;your smtp server details&quot;;
SmtpMail.Send(mail);&lt;/strike&gt;
//Scrub that bit above, you should use system.net.mail instead.
// Send the email.
SmtpClient client = new SmtpClient(&quot;your smtp server address&quot;, portnumber);
client.Send(mail);</pre>


这篇关于通过基于C#桌面的应用程序发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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