1
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
57
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
using System.Net;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Send_Gmail(textBox1.Text, "測試主題", "收件人地址");
}
public void Send_Gmail(string msg, string mysubject, string address)
{
MailMessage mmsg = new MailMessage("寄件人地址", address);
mmsg.IsBodyHtml = true;
mmsg.BodyEncoding = Encoding.UTF8;
mmsg.SubjectEncoding = Encoding.UTF8;
mmsg.Priority = MailPriority.Normal;
mmsg.Subject = mysubject;
mmsg.Body = msg;
SmtpClient MySmtp = new SmtpClient("smtp.gmail.com", 587);
MySmtp.Credentials = new NetworkCredential("帳號", "密碼");
MySmtp.EnableSsl = true;
MySmtp.Send(mmsg);
MySmtp = null;
mmsg.Dispose();
}
}
}
|