C#-mail寄送附件
在C#寫寄送mail的程式不算因難,
只是會遇到客戶一些要求,
今天替客戶寫一個寄送附件的功能,
我們的做法是先建立一個「目錄」,
在這「目錄」中新建「檔案」,
最後再將「檔案」寄出。
using System.IO;
/// <summary>
/// 產生加附檔
/// </summary>
public void SETATTACH()
{
System.IO.Directory.CreateDirectory(@"c:\MAIL寄發");
SaveFileDialog sfd = new SaveFileDialog();
sfd.FileName = "附件";//檔名
string filename = @"C:\\MAIL寄發\\" + sfd.FileName + ".rtf";
FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write);
StreamWriter bw = new StreamWriter(fs);
bw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("UTF-8"));
try
{
System.Windows.Forms.Application.DoEvents();
//將HTML語法存入DOC檔
bw.Write(SETBODY("Y"));
bw.Write("\r\n");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
bw.Close();
fs.Close();
}
自我LV~