using System.Net.Mail; string id = hsEmailKey[txtEmail.Text].ToString(); MailAddress from = new System.Net.Mail.MailAddress("XXX@gmail.com", "顯示名稱", System.Text.Encoding.UTF8);//自身gmail地址 MailAddress to = new System.Net.Mail.MailAddress("對方mail地址", "二手書交流平台", System.Text.Encoding.UTF8);//對方mail地址 MailMessage em = new MailMessage(from,to); em.SubjectEncoding = System.Text.Encoding.UTF8;//主旨編碼 em.BodyEncoding = Encoding.UTF8;//內容編碼 em.Subject = "來自二手書交流平台重要訊息";//主旨 em.Body = String.Format("下面是您的帳號、密碼:\n註冊帳號:{0}\n註冊密碼:{1}\n請妥善保管以利快速登入", id, ((RegisterInformation)hsLogin[id]).getPass());//內文 System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(); client.Credentials = new System.Net.NetworkCredential("XXX@gmail.com", "gmail密碼");//自己的 client.Port = 587;//設定port client