標籤:io ar os 使用 sp for on div art
附件大,上傳,發送一定會慢.程式卡,應該是主線程正在發送,郵件造成的.建立其他線程在後台去發.這樣就不影響主線程做其他工作了 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Net.Mail;namespace WindowsFormsApplication1{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { MailMessage MailMessage = new MailMessage(); //這個是我們的郵件對象,包含主題,內容等主要屬性 SmtpClient SmtpServer = new SmtpClient(); //這個是我們的SMTP用戶端對象,通過這個對象將我們的郵件發送出去 MailMessage.From = new MailAddress("[email protected]","網站郵件", System.Text.Encoding.UTF8); //例如[email protected] ‘MailMessage對象的From屬性意為郵件的寄件者,顧名思義在此處設定郵件的寄件者. MailMessage.To.Add("[email protected]"); //例如[email protected] ‘MailMessage對象的To屬性意為該郵件的收件者集合,使用該屬性的Add方法來添加收件者 MailMessage.Subject = "大家好!~我是郵件標題"; //Subject屬性就是郵件的標題內容 //MailMessage.Body = "大家好!~我是郵件內容" ‘Body屬性是郵件的內容 MailMessage.Priority = MailPriority.Normal; //Normal是普通優先順序,這裡還可以設定成High或Low SmtpServer.Host = "SMTP.qq.com"; //這裡設定我們的SMTP伺服器,例如smtp.163.com SmtpServer.Credentials = new System.Net.NetworkCredential("9520848", "nnnnnnnnnnnnn"); //這裡的使用者名稱和密碼用於SMTP伺服器認證 //SmtpServer.Timeout = 100 ‘設定發送逾時的時間,預設是100秒 MailMessage.Attachments.Add(new Attachment("c:\\網頁.txt")); MailMessage.Attachments.Add(new Attachment("G:\\Ultt_SC17.rar")); MailMessage.Body = "111111111111"; SmtpServer.Send(MailMessage); } }}
發現用System.Net.Mail發郵件(代碼附後),附件稍微大一點就會造成程式假死. 有沒有什麼簡單的解決辦法呢? 多謝!!