日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

读Excel发送工资条小工具

發布時間:2023/12/14 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 读Excel发送工资条小工具 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

臨時需要開發的一個通過excel發送附件工資條的工具

1. 讀取excel 模板郵箱發送郵件

2. 薪資項是生成的附件htm文件

3. 發送成功和失敗記錄有日志記載

預覽:

核心代碼:

//發件人地址
MailAddress from = new MailAddress(fromEmail, fromEmail);

//收件人地址
MailAddress to = new MailAddress(emailTo);

MailMessage message
= new MailMessage(from, to);

message.Subject
= System.Configuration.ConfigurationManager.AppSettings["SUBJECT"].ToString();//"3月薪資單、注意保密";

message.IsBodyHtml
= true;
message.BodyEncoding
= System.Text.Encoding.UTF8;

message.Body
= "body";
message.Body
= "薪資請見附件";

string smtpserver = System.Configuration.ConfigurationManager.AppSettings["SMTP"].ToString();//"smtp.live.com";
int smtpport = 25;
bool isssl = false;
SmtpClient client
= new SmtpClient(smtpserver, smtpport);

if (chbSafe.Checked)
{
isssl
= true;
}
client.EnableSsl
= isssl;
client.DeliveryMethod
= SmtpDeliveryMethod.Network;
client.UseDefaultCredentials
= false;
client.Credentials
= new System.Net.NetworkCredential(fromEmail, passWord);
client.Timeout
= 100000000;

byte[] array = Encoding.ASCII.GetBytes(msg);
MemoryStream stream
= new MemoryStream(array); //convert stream 2 string
StreamReader reader = new StreamReader(stream);

Attachment data
= Attachment.CreateAttachmentFromString(msg, name + ".htm", Encoding.Default,null);

message.Attachments.Add(data);

try
{
client.Send(message);

//for (int i = 0; i < 100; i++)
{
log4net.ILog log
= log4net.LogManager.GetLogger("log");

log.Info(count
+ " Info:" + "員工:" + name + " 郵件:" + emailTo + "-----" + "ok!");

count
++;
}
}
catch (IndexOutOfRangeException e)
{
MessageBox.Show(e.Message);
}
catch (Exception ee)
{
log4net.ILog log
= log4net.LogManager.GetLogger("log");
log.Error(
"error", new Exception("員工:" + name + " 郵件:" + emailTo + "-----" + "error!" + ee.Message));

}

完整代碼:http://files.cnblogs.com/agtaimaer/WMEmail.rar

轉載于:https://www.cnblogs.com/agtaimaer/archive/2011/04/11/2012323.html

總結

以上是生活随笔為你收集整理的读Excel发送工资条小工具的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。