1
using System;
2
using System.Text;
3
using System.Net.Mail;
4
using System.Configuration;
5
6
/// <summary>
7
/// Email 的摘要说明
8
/// </summary>
9
public class Email
10
{
11
/// <summary>
12
/// 郵件發送函數(靜態)
13
/// </summary>
14
/// <param name="mailFromAddress">發送人郵件地址</param>
15
/// <param name="mailFromName">發送人名稱</param>
16
/// <param name="mailTo">收件人</param>
17
/// <param name="mailCc">抄送人</param>
18
/// <param name="mailSubject">主題</param>
19
/// <param name="mailBody">郵件內容</param>
20
public static void SendMail(string mailFromAddress, string mailFromName, string mailTo, string mailCc, string mailSubject, string mailBody)
21
{
22
//create the mail message
23
MailMessage mail = new MailMessage();
24
25
//set the addresses
26
mail.From = new MailAddress(mailFromAddress, mailFromName);
27
28
mail.To.Add(mailTo);
29
mail.CC.Add(mailCc); ;
30
//mail.Bcc.Add("sfwu@cclmotors.com");
31
32
//set the content
33
mail.Subject = mailSubject;
34
mail.Body = mailBody;
35
//add an attachment from the filesystem
36
//mail.Attachments.Add(new Attachment("c:\\temp\\example.txt"));
37
38
mail.IsBodyHtml = true;
39
40
//specify the priority of the mail message
41
//mail.Priority = MailPriority.High;
42
43
//In this example we use the utf-8 characterset
44
mail.BodyEncoding = Encoding.GetEncoding("utf-8");
45
46
//send the message
47
SmtpClient smtp = new SmtpClient(ConfigurationManager.AppSettings["MailStr"]);
48
//to authenticate we set the username and password properites on the SmtpClient
49
//smtp.Credentials = new NetworkCredential("username", "secret");
50
//to change the port (default is 25), we set the port property
51
//smtp.Port = 587;
52
//smtp.EnableSsl = true;
53
smtp.Send(mail);
54
}
55
}
56
带SMTP验证的类
2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56






























































































































































