使用批处理文件发送电子邮件

时间:2014-01-17 11:41:48

标签: batch-file

我的Outlook配置了我的办公室ID,对批处理脚本来说非常新。通过批处理文件向我的同事发送电子邮件的最简单方法(最简单的代码)是什么。

谢谢

1 个答案:

答案 0 :(得分:2)

我可以看到3个选项:

  1. 底线是批量没有内置方式,但是可以从批处理文件中调用像blat等第三方工具。

  2. 您可以启用已安装的Windows SMTP服务器。然后运行Powershell脚本:

    $smtpServer = "system.abc.com"
    $smtpFrom = "dontreply@abc.com"
    $smtpTo = "something@abc.com"
    $messageSubject = "Put your subject here"
    
    $message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
    $message.Subject = $messageSubject
    $message.IsBodyHTML = $true
    $message.Body = Get-Content debug.txt
    
    $smtp = New-Object Net.Mail.SmtpClient($smtpServer)
    $smtp.Send($message)
    
  3. 您可以启用已安装的Windows SMTP服务器。然后运行VBScript:

    Const ForReading = 1
    Const ForWriting = 2
    Const ForAppending = 8
    Const FileToBeUsed = "debug.txt"
    Dim objCDO1
    Dim fso, f
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.OpenTextFile(FileToBeUsed, ForReading)
    Set objCDO1 = CreateObject("CDO.Message")
    objCDO1.Textbody = f.ReadAll
    f.Close
    objCDO1.TO ="something@abc.com"
    objCDO1.From = "dontreply@abc.com"
    objCDO1.Subject = "Put your subject here"
    objCDO1.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration /sendusing") = 2 
    objCDO1.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration /smtpserver") = "system.abc.com"
    objCDO1.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration /smtpserverport") = 25 
    objCDO1.Configuration.Fields.Update     
    objCDO1.Send
    Set f = Nothing
    Set fso = Nothing
    
  4. 选择是你的。