TRE Common Mail

本文介绍了一个使用批处理脚本和CDO组件实现的邮件发送工具Tre-MailSend,该工具可以设置邮件服务器、发件人地址,并通过命令行交互方式让用户输入收件人、主题、正文内容等信息。此外,还支持附件添加功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

@echo off & setlocal enabledelayedexpansion
title Tre-Mail Send (version2)
echo.
echo ------------------------WelCome To Tre-Mail Send-------------------------------
echo.


set EmailServer="'192.168.1.210'"
set EmailFrom='RPWT-Manager@china.tre-inc.com'
rem set EmailAttachment1="'%folder:"=%/%temp%/Email.log'"
rem set EmailAttachment2="'%folder:"=%/"%today%Export.log"'"
rem set folder=%cd%
rem cd %folder%
echo NameSpace="http://schemas.microsoft.com/cdo/configuration/" >%temp%/Email_Schema.xml
echo set Email=CreateObject("CDO.Message") >>%temp%/Email_Schema.xml
echo Email.From=#@EmailFrom >>%temp%/Email_Schema.xml
echo Email.to=#@EmailTo >>%temp%/Email_Schema.xml
echo Email.Subject=#@EmailSubject >>%temp%/Email_Schema.xml
echo Email.Textbody=date^&"  "^&time^&" "^&vbcrlf^&#@EmailText >>%temp%/Email_Schema.xml
echo Email.AddAttachment #@EmailAttachment1 >>%temp%/Email_Schema.xml
echo Email.AddAttachment #@EmailAttachment2 >>%temp%/Email_Schema.xml
echo with Email.Configuration.Fields >>%temp%/Email_Schema.xml
echo .Item(NameSpace^&"sendusing")=2 >>%temp%/Email_Schema.xml
echo .Item(NameSpace^&"smtpserver")=#@EmailServer >>%temp%/Email_Schema.xml
echo .Item(NameSpace^&"smtpserverpot")=25 >>%temp%/Email_Schema.xml
echo .Item(NameSpace^&"smtpauthenticate")=1 >>%temp%/Email_Schema.xml
echo .Update >>%temp%/Email_Schema.xml
echo end with >>%temp%/Email_Schema.xml
echo Email.Send >>%temp%/Email_Schema.xml


:_SetEmailTo
set EmailTo=
set /p EmailTo=収信人(xxx@china.tre-inc.comによって) :
if /i not "%EmailTo:~-18%"=="@china.tre-inc.com" (
    echo MailFormat Error & goto :_SetEmailTo
)
set EmailTo="'%EmailTo:"=''%'"
goto :_SetEmailSubject

:_SetEmailSubject
set EmailSubject=
set /p EmailSubject=Subject :
if defined EmailSubject (
    set EmailSubject="'%EmailSubject:"=''%'"
    goto :_SetEmailText
)
goto :_SetEmailSubject

:_SetEmailText
set EmailText=
set /p EmailText=Text (轉行符が /n です):
if defined EmailText (
    set EmailText="'%EmailText:"=''%'"
    goto :_AddAttach
)
goto :_SetEmailText

:_AddAttach
set Att=
set /p Att=Are U Want To Add Attachment ?(Y/N)
if /i "%Att%"=="y" (
    goto :_SetAttachment
)else if /i "%Att%"=="n" goto :_SendMail
goto :_AddAttach

:_SetAttachment
set EmailAttachment1=
set /p EmailAttachment1=Attachment (D:/Email/%temp%/Email.log によって) :
if defined EmailAttachment1 (
    set EmailAttachment1="'%EmailAttachment1:"=''%'"
    goto :_SendMail
)else goto :_AddAttach

:_SendMail
date /T >>%temp%/Email.log
time /T >>%temp%/Email.log
copy /y %temp%/Email_Schema.xml %temp%/Email.vbs >nul
call :_Replace %temp%/Email.vbs #@EmailServer %EmailServer%
call :_Replace %temp%/Email.vbs #@EmailFrom %EmailFrom%
call :_Replace %temp%/Email.vbs #@EmailTo %EmailTo%
call :_Replace %temp%/Email.vbs #@EmailSubject %EmailSubject%
call :_Replace %temp%/Email.vbs #@EmailText %EmailText%

if not defined EmailAttachment1 (
    call :_Replace %temp%/Email.vbs "Email.AddAttachment #@EmailAttachment1"
)else call :_Replace %temp%/Email.vbs #@EmailAttachment1 %EmailAttachment1%

if not defined EmailAttachment2 (
    call :_Replace %temp%/Email.vbs "Email.AddAttachment #@EmailAttachment2"
)else call :_Replace %temp%/Email.vbs #@EmailAttachment2 %EmailAttachment2%

echo.
echo Sending Mail……
echo Sending Mail…… >>%temp%/Email.log
for /f "tokens=*" %%i in (%temp%/Email.vbs) do echo         %%i >>%temp%/Email.log
cscript %temp%/Email.vbs >nul
if errorlevel 1 (
    echo Sorry , Send Failure...
    echo Sorry , Send Failure... >>%temp%/Email.log
)else (
    echo Send Successful...
    echo Send Successful... >>%temp%/Email.log
)
del %temp%/Email.vbs
echo.
echo ------------------------Thank U for Using Tre-Mail Send------------------------
echo.
goto :_Continue


:_Continue
set Continue=
set /p Continue=Are U Want To Go On ?(Y/N)
if /i "%Continue%"=="y" (
    goto :_SetEmailTo   
)else if /i "%Continue%"=="n" goto :_End
goto :_Continue


:_Replace
set file=%1
set strS=%2
if defined strS set strS=%strS:"=%
set strR=%3
if defined strR set strR=%strR:"=%
if defined strR set strR=%strR:'="%
if defined strR set strR=%strR:/n="^^^&vbcrlf^^^&"%
for /f "tokens=*" %%i in (%file%) do (
    set _str=%%i
    if defined _str set _str=!_str:%strS%=%strR%!
    if defined _str if not "!_str: =!"=="" echo !_str!>>%temp%/_tmp.txt
)
move /Y %temp%/_tmp.txt %file%
goto :EOF


:_End
date /t >>%temp%/Email.log
time /t >>%temp%/Email.log
echo ---------end---------->>%temp%/Email.log
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值