标题: [其他] 给财务的同事写的批量发送工资详情邮件的批处理 [打印本页]
作者: amwfjhh 时间: 2015-1-23 15:01 标题: 给财务的同事写的批量发送工资详情邮件的批处理
本帖最后由 amwfjhh 于 2015-1-23 15:06 编辑
财务每个月要统计每个人工资详情,会有一张工资明细表,反正有这个数据,就在此基础上帮她们写个批量发送邮件的批处理。需要用到两个文件:
工资明细.csv,形如以下格式- 姓名,卡号,基本工资,住房补贴,浮动,预付奖金,双薪,加班、其他等,小计,住房金,其他,考勤,税前合计,计算所得税金额,税,应发数,已发,实发数
- 赵一,6222611111111111111,2600,400,1000,3000,3000,200,10200,180,,,10020,6520,749,9271,,9271
- 钱二,6222611111111112222,2600,400,500,3000,3000,100,9600,180,,,9420,5920,629,8791,,8791
- 孙三,6222611111111113333,2500,,500,3000,2500,100,8600,150,,,8450,4950,435,8015,,8015
- 李四,6222611111111114444,4000,,1000,3000,,,8000,240,,,7760,4260,321,7439,,7439
- 周五,6222611111111115555,4000,,1000,3000,,,8000,240,,,7760,4260,321,7439,,7439
复制代码
名单.csv,形如以下格式- 姓名,邮箱,电话
- 赵一,aaa@QQ.COM,13811111111
- 钱二,bbb@qq.com,18622222222
- 孙三,ccc@qq.com,13833333333
- 李四,ddd@qq.com,13044444444
- 周五,eee@qq.com,13855555555
复制代码
发送邮件需要用到第三方邮件工具,blat,可于其官网上下载,本论坛有介绍http://bbs.bathome.net/viewthread.php?tid=7465&highlight=blat。
实际应用中由于财务的工作分区是NTFS格式的,为了避免其拷贝时忘了附带上blat.exe,于是将其附于批处理本身的流文件中。type blat.exe>"batfile.bat:blat.exe",
具体代码如下:- @if (0)==(0) echo off
- setlocal enabledelayedexpansion
- chcp 437&graftabl 936
-
- REM 变量初始化
- prompt $
- title **工资详情批量发送工具.::By KOUKON::.
- COLOR 9e
- :_start
- cls
- set /p "from=请输入你的邮箱地址:"
- echo,%from% | findstr ".*@[0-9a-zA-Z]*\.[0-9a-zA-Z]*.*" >nul 2>nul || (
- echo,不合法邮箱地址,请重新输入...
- pause
- goto :_start
- )
- for /f "tokens=1,* delims=@" %%i in ('echo %from%') do (
- set "user=%%i"
- set "server=smtp.%%j"
- )
- echo,用户名 : %user%
- echo,服务器 : %server%
- set/p"=请输入邮箱登录密码:"<nul
- REM 生成取得字符程序
- pushd %tmp%
- echo,hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5x>in.com
- for /f "tokens=*" %%a in ('in.com') do (
- set "pass=%%a"
- )
- del /f in.com
- popd
- echo,
- REM echo,密码 : !pass!
- :_next
- REM set /p "to=请输入你要发送的邮箱:"
- set "x=X-Header-Test "Can Blat do it Yes it Can!""
- set "debug=-log MailLog.log -timestamp "
- cd.>MailLog.log
-
-
- REM 获取详情
- set /p "strFile=拖入整理好的工资条列表(csv格式文件):"
- :_readContent
- echo,下面开始读取工资详情……
- echo,&echo,
- for /f "skip=1 tokens=*" %%u in ('type %strFile%') do (
- set "Line=%%u"
- REM cscript -nologo -e:jscript %~s0 DealNullChar "!Line!"
- for /f "tokens=*" %%v in ('cscript -nologo -e:jscript %~s0 DealNullChar "!Line!"') do set "Line=%%v"
- REM echo,处理后内容 : !Line!
- for /f "tokens=1-18 delims=," %%a in ('echo,!Line!') do (
- (
- echo,%%a:
- echo, 您好。这是本月工资详单,请查阅。
- set/p"=姓 名 : "<nul
- if "%%a" NEQ "null" (echo,%%a) else echo,
- set/p"=卡 号 : "<nul
- if "%%b" NEQ "null" (echo,%%b) else echo,
- set/p"=基本工资 : "<nul
- if "%%c" NEQ "null" (echo,%%c) else echo,
- set/p"=住房补贴 : "<nul
- if "%%d" NEQ "null" (echo,%%d) else echo,
- set/p"=浮 动 : "<nul
- if "%%e" NEQ "null" (echo,%%e) else echo,
- set/p"=预付奖金 : "<nul
- if "%%f" NEQ "null" (echo,%%f) else echo,
- set/p"=奖 金 : "<nul
- if "%%g" NEQ "null" (echo,%%g) else echo,
- set/p"=加班其它 : "<nul
- if "%%h" NEQ "null" (echo,%%h) else echo,
- set/p"=小 计 : "<nul
- if "%%i" NEQ "null" (echo,%%i) else echo,
- set/p"=住 房 金 : "<nul
- if "%%j" NEQ "null" (echo,%%j) else echo,
- set/p"=其 他 : "<nul
- if "%%k" NEQ "null" (echo,%%k) else echo,
- set/p"=考 勤 : "<nul
- if "%%l" NEQ "null" (echo,%%l) else echo,
- set/p"=税前合计 : "<nul
- if "%%m" NEQ "null" (echo,%%m) else echo,
- set/p"=计税金额 : "<nul
- if "%%n" NEQ "null" (echo,%%n) else echo,
- set/p"=扣 税 : "<nul
- if "%%o" NEQ "null" (echo,%%o) else echo,
- set/p"=应 发 数 : "<nul
- if "%%p" NEQ "null" (echo,%%p) else echo,
- set/p"=已 发 : "<nul
- if "%%q" NEQ "null" (echo,%%q) else echo,
- set/p"=实 发 数 : "<nul
- if "%%r" NEQ "null" (echo,%%r) else echo,
- echo, ****公司 财务部
- echo, %date%
- ) >"mailBody.dat"
- REM find /v ""<"mailBody.dat"
- REM ECHO,%%a, %%b, %%c, %%d, %%e, %%f, %%g, %%h, %%i, %%j, %%k, %%l, %%m, %%n, %%o, %%p, %%q, %%r
- set "strName="
- set "strMail="
- set "strTel="
- for /f "tokens=*" %%w in ('findstr /c:"%%a" 名单.csv') do (
- for /f "tokens=1-3 delims=," %%1 in ('cscript -nologo -e:jscript %~s0 DealNullChar "%%~w"') do (
- echo,姓名 : %%1
- echo,邮箱 : %%2
- echo,手机 : %%3
- set "subj=%%1 工资详单"
- if "%%1" NEQ "" if "%%1" NEQ "null" set "strName=%%1"
- if "%%2" NEQ "" if "%%2" NEQ "null" set "strMail=%%2"
- if "%%3" NEQ "" if "%%3" NEQ "null" set "strTel=%%3"
- )
- )
- REM echo,strName : !strName!
- REM echo,strMail : !strMail!
- REM echo,strTel : !strTel!
-
- if "!strName!" NEQ "" (
- echo,发送邮件至 !strMail!
- if "!strMail!" NEQ "" (
- start "" /WAIT /b %~s0:blat.exe -server %server% -u %user% -pw %pass% -f %from% -to "!strMail!" -s "!subj!" -bodyF "mailBody.dat" -charset "GBK" -debug %debug%
- ) else (
- echo,未检测到登记邮箱,跳过此步骤
- )
-
- echo,检测手机号
- if "!strTel!" NEQ "" (
- for /f "tokens=*" %%z in ('cscript -nologo -e:jscript %~s0 IsCM "!strTel!"') do (
- if %%z NEQ 0 (
- echo,当前用户手机号为移动号码,可以推送至手机邮箱
- start "" /WAIT /b %~s0:blat.exe -server %server% -u %user% -pw %pass% -f %from% -to "!strTel!@139.com" -s "!subj! 手机推送" -bodyF "mailBody.dat" -charset "GBK" -debug %debug%
- ) else (
- echo,非移动手机号,跳过手机推送步骤
- )
- )
- ) else (
- echo,未登记手机号,跳过此步骤
- )
- ) else (
- echo,★★★当前统计人员【%%a】:该条工资明细无登记联系方式,跳过邮件发送步骤★★★
- )
-
- echo,&echo,
- )
- )
-
-
- pause>nul
- del /f "mailBody.dat"
- goto :EOF
-
- @end
-
- var fun = WScript.arguments(0);
- switch (fun){
- case "IsCM":
- CheckArgs(2);
- var strTel = WScript.arguments(1);
- IsCM(strTel);
- break;
-
- case "DealNullChar":
- CheckArgs(2);
- var strContent = WScript.arguments(1);
- DealNullChar(strContent);
- break;
-
- case "RegTest":
- CheckArgs(2);
- var strContent = WScript.arguments(1);
- RegTest(strContent);
- break;
-
- default:;
- }
-
- function CheckArgs(num){
- if (WScript.arguments.length < num){
- WScript.echo("参数不齐");
- WScript.quit();
- }
- }
-
- function IsCM(strTel){
- var reg = /^(\+86)?1((3[4-9])||(5[0-28-9])||(8[278]))\d{8}$/g;
- WScript.echo(reg.test(strTel));
- }
-
- function DealNullChar(strContent){
- var reg = /,,/g;
- while (true) {
- strContent = strContent.replace(reg, ",null,");
- //WScript.echo("处理后结果 : " + strContent);
- var ret = RegTest(strContent);
- //WScript.echo("正则 " + reg + " 符合度判断结果 : " + ret);
- if (!ret) break;
- }
- WScript.echo(strContent);
- }
-
- function RegTest(strContent){
- var reg = /,,/g;
- var ret = reg.test(strContent);
- //WScript.echo(ret);
-
- return ret;
- }
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |