具体发送邮件的命名空间System.Net.Mail下有很多方法,下面是复制的代码;
具体的界面自己画一下就可以了,应该看的懂,具体代码如下:
具体的界面自己画一下就可以了,应该看的懂,具体代码如下:
1
private void button1_Click(object sender, EventArgs e)
2![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
{//发送
4![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
string strRecieveEMail = txtRecieveEMail.Text.Trim();
6![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
string strSendEmail = txtSendEMail.Text.Trim();
8![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
string strSubject = txtSubject.Text.Trim();
10![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
string strBody = txtBody.Text.Trim();
12![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
14![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
16![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
msg.To.Add(strRecieveEMail);
18![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
20![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
21
//System.Net.Mail.MailAddress mAdd =
22![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
23
24![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
if(txtAttachment.Text.Trim().Length > 0)
26![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27
{
28![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
29
string FileName = txtAttachment.Text.Trim();
30![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
31
System.Net.Mail.Attachment pAttachment = new Attachment(FileName);
32![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
33
msg.Attachments.Add(pAttachment);
34![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
35
}
36![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
37
38![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
39
msg.From = new MailAddress(strSendEmail, strSendEmail, System.Text.Encoding.UTF8);;
40![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
41
/* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/
42![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
43
msg.Subject = strSubject;//邮件标题
44![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
45
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
46![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
47
msg.Body = strBody;//邮件内容
48![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
49
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
50![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
51
msg.IsBodyHtml = false;//是否是HTML邮件
52![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
53
msg.Priority = MailPriority.High;//邮件优先级
54![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
55
56![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
57
58![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
59
SmtpClient client = new SmtpClient();
60![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
61
client.Host = txtSmtp.Text.Trim();//这个非常重要,为邮件服务器设置
62![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
63
64![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
65
object userState = msg;
66![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
67
try
68![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
69
{
70![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
71
client.SendAsync(msg, userState); //简单一点儿可以client.Send(msg);
72![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
73
MessageBox.Show("成功发送到" + strRecieveEMail + "邮箱");
74![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
75
}
76![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
77
catch (System.Net.Mail.SmtpException ex)
78![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
79
{
80![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
81
MessageBox.Show(ex.Message, "发送邮件出错");
82![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
83
}
84![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
85
}
86![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
29
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
30
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
31
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
32
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
33
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
34
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
35
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
36
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
37
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
38
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
39
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
40
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
41
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
42
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
43
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
44
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
45
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
46
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
47
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
48
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
49
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
50
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
51
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
52
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
53
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
54
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
55
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
56
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
57
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
58
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
59
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
60
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
61
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
62
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
63
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
64
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
65
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
66
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
67
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
68
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
69
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
70
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
71
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
72
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
73
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
74
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
75
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
76
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
77
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
78
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
79
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
80
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
81
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
82
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
83
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
84
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
85
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
86
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)