jay*_*t55 2 c# windows email send winforms
大约一年了,我在尝试使用Visual C#以编程方式发送和接收电子邮件时遇到了问题.我在网上发现的数百个例子中没有一个例子.不,我不只是复制和粘贴.我研究代码,并根据需要修改/添加/删除.
有人可以帮我解决这个问题.我正在努力完成一个应该是我去年开始制作的简单程序,而且事实证明我几乎不可能弄明白.
老实说,我不知道该怎么做了.该文档没有向我提供任何有用的信息,因为它没有任何工作.我已经将示例代码提供给其他人使用,它适用于他们 - 但不是我!这是如何运作的?
我不知道SENDING邮件是否依赖于我的计算机具有的安全/防火墙设置.但就这种情况而言,我甚至暂时完全关闭所有安全和防火墙设置,以确定它是否会发送电子邮件.
我已经没有代码了,因为我刚刚开始尝试再次做这件事,如果有人能帮我完成这项工作,我真的很感激.
所以,我要做的就是:
使用2个按钮和一个文本框创建一个简单的表单.(完成,当然)
button1检查电子邮件(但只在消息框中显示主题和发件人,不下载消息)
button2将textBox1的内容发送到" username@bluebottle.com"
我的服务器设置是:
Username username@bluebottle.com
Password ***********
IMAP/POP Server (Incoming): mail.bluebottle.com
SMTP Server (Outgoing): mail.bluebottle.com
SMTP should be port 25, 26 or 587
POP3 should be port 110, using SSL 995
IMAP should be port 143, using SSL 993
Run Code Online (Sandbox Code Playgroud)
没关系.我只是为自己弄清楚了.这是一个简单的123!还是ABC?我忘了它是怎么回事.任何人如何感兴趣或需要知道如何用C#发送电子邮件,这对我来说是有用的:
string Sender = "username@domain.com";
string Username = "username";
string Password = "********";
string Recipient = "username@domain.com";
string Subject = "Enter subject here.";
string Message = "Enter message here.";
string Host = "mail.server.com";
int Port = 26;
using(MailMessage Mail =
new MailMessage(
Sender,
Recipient))
using (SmtpClient SmtpMail =
new SmtpClient(
Host,
Port))
{
Mail.Subject = Subject;
Mail.Body = Message;
SmtpMail.EnableSsl = true;
SmtpMail.Credentials =
new System.Net.NetworkCredential(
Username,
Password);
SmtpMail.Send(Mail);
}
Run Code Online (Sandbox Code Playgroud)
using System.Net.Mail;
Run Code Online (Sandbox Code Playgroud)
编辑:使用模式docos:http://msdn.microsoft.com/en-us/library/yh598w02( VS.71).aspx
| 归档时间: |
|
| 查看次数: |
2349 次 |
| 最近记录: |