c# 傳送郵件程式碼,帶附件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;
using System.Diagnostics;
namespace Test28
{
class Program
{
static void Main(string[] args)
{
Email email = new Email()
{
fromEmail = "傳送人郵箱",
fromPerson = "發件人",
toEmail = "接收人郵箱",
toPerson = "接收人",
encoding = "UTF-8",
smtpServer = "選用的郵件伺服器平【比如:mail.163.com】",
userName = "你郵箱的使用者名稱【比如:xxxxx@163.com】",
passWord = "你的郵箱的密碼",
emailTitle = "郵件標題",
emailContent = "郵件內容"
};
SendEmail(email);
}
#region 郵件傳送程式碼
/// <summary>
/// 郵件傳送程式碼
/// </summary>
/// <param name="email"></param>
public static void SendEmail(Email email)
{
//try
//{
//設定發件人信箱,及顯示名字
MailAddress from = new MailAddress(email.fromEmail, email.fromPerson);
//設定收件人信箱,及顯示名字
MailAddress to = new MailAddress(email.toEmail, email.toPerson);
//建立一個MailMessage物件
MailMessage oMail = new MailMessage(from, to);
oMail.Subject = email.emailTitle; //郵件標題
oMail.Body = email.emailContent; //郵件內容
oMail.IsBodyHtml = true; //指定郵件格式,支援HTML格式
System.Net.Mail.Attachment mailAttach_1 = new Attachment(@"c:\UserCenterLog.txt");//附件
oMail.Attachments.Add(mailAttach_1);
oMail.BodyEncoding = System.Text.Encoding.GetEncoding(email.encoding);//郵件採用的編碼
oMail.Priority = MailPriority.High;//設定郵件的優先順序為高
//傳送郵件伺服器
SmtpClient client = new SmtpClient();
client.Host = email.smtpServer; //指定郵件伺服器
client.Credentials = new NetworkCredential(email.userName, email.passWord);//指定伺服器郵件,及密碼
//傳送
client.Send(oMail); //傳送郵件
oMail.Dispose(); //釋放資源
//}
//catch(Exception ex)
//{
// StreamWriter writer = File.AppendText(@"c:\00.txt");
// writer.WriteLine(ex.Message);
// writer.Close();
// writer.Dispose();
//}
//finally
//{
//}
}
#endregion
}
class Email
{
public string fromEmail { get; set; }
public string fromPerson { get; set; }
public string toEmail { get; set; }
public string toPerson { get; set; }
public string encoding { get; set; }
public string smtpServer { get; set; }
public string userName { get; set; }
public string passWord { get; set; }
public string emailTitle { get; set; }
public string emailContent { get; set; }
}
}
相關文章
- Java郵件傳送帶附件Java
- Python 傳送帶有附件的郵件Python
- linux shell傳送帶附件的郵件Linux
- 【主機】sendEmail傳送帶有附件的郵件AI
- 如何使用 ABAP 程式碼傳送帶有 PDF 附件的電子郵件
- C# - MailSender 郵件傳送元件原始碼 (支援ESMTP, 附件) (轉)C#AI元件原始碼
- 【python】用SMTP模組傳送帶附件的郵件Python
- 利用Jmail傳送帶附件的郵件時亂碼的解決方案AI
- Mac郵件怎麼傳送超大附件Mac
- 使用C#傳送正文帶圖片郵件C#
- 如何使用ABAP傳送帶有PDF格式附件的電子郵件
- Linux自動下傳送HTML格式並帶附件的郵件LinuxHTML
- 使用C#傳送郵件C#
- Python2.7 smtplib傳送帶附件郵件報錯STARTTLS解PythonTLS
- C# 傳送電子郵件原始碼片段C#原始碼
- 傳送帶圖片的郵件
- C#原生郵件傳送+傳送日誌記錄C#
- 自動生成AWR報告並以郵件附件傳送
- 郵件傳送庫原始碼原始碼
- 郵件開發:傳送程式
- 郵件傳送
- 傳送郵件
- 用shell指令碼傳送帶附件的email指令碼AI
- iOS12系統應用傳送郵件中的附件iOS
- 谷歌郵箱,配置傳送郵件密碼谷歌密碼
- laravel 傳送郵件修改密碼Laravel密碼
- SpringBoot整合Mail傳送郵件&傳送模板郵件Spring BootAI
- asp.net傳送郵件程式ASP.NET
- Laravel 傳送郵件Laravel
- PHP傳送郵件PHP
- Django——郵件傳送Django
- java郵件傳送Java
- Laravel傳送郵件Laravel
- gmail傳送郵件AI
- Oracle郵件傳送Oracle
- java傳送郵件Java
- Powershell郵件傳送
- thinkphp 郵件傳送PHP