Send mail from a Windows script

前端 未结 7 863
耶瑟儿~
耶瑟儿~ 2021-01-02 07:11

I would like to send mail from a script on a Windows Server 2003 Standard Edition. I think the server setup is pretty much out of the box.

The mail server is an Exch

相关标签:
7条回答
  • 2021-01-02 07:47

    If you have outlook/exchange installed you should be able to use CDONTs, just create a mail.vbs file and call it in a batch file like so (amusing they are in the same dir)

    wscript mail.vbs
    

    for the VBScript code check out

    http://support.microsoft.com/kb/197920

    http://www.w3schools.com/asp/asp_send_email.asp

    forget the fact they the two links speak about ASP, it should work fine as a stand alone script with out iis.

    0 讨论(0)
  • 2021-01-02 07:47

    Use CDONTS with Windows Scripting Host (WScript)

    0 讨论(0)
  • 2021-01-02 08:00

    Is there a way you send without referencing the outside schema urls. http://schemas.microsoft.com/cdo/configuration/

    That is highly useless as it can't be assumed all boxes will have outside internet access to send mail internally on the local exchange. Is there a way to save the info from those urls locally?

    0 讨论(0)
  • 2021-01-02 08:03

    I think that you'll have to install some ActiveX or other component what could be invoked from WScript, such as: http://www.activexperts.com/ActivEmail/ and: http://www.emailarchitect.net/webapp/SMTPCOM/developers/scripting.asp

    Otherwise, you'll have to write the entire SMTP logic (if possible, not sure) in WScript all on your own.

    0 讨论(0)
  • 2021-01-02 08:04

    I don't know if dropping a binary alongside the .bat file counts as installing software, but, if not, you can use blat to do this.

    0 讨论(0)
  • 2021-01-02 08:07

    It is possible with Wscript, using CDO:

    Dim objMail
    
    Set objMail = CreateObject("CDO.Message")
    
    objMail.From = "Me <Me@Server.com>"
    objMail.To = "You <You@AnotherServer.com>"
    objMail.Subject = "That's a mail"
    objMail.Textbody = "Hello World"
    objMail.AddAttachment "C:\someFile.ext"
    
    ---8<----- You don't need this part if you have an active Outlook [Express] account -----
    ' Use an SMTP server
    objMail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    
    ' Name or IP of Remote SMTP Server
    objMail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
        "smtp.server.com"
    
    ' Server port (typically 25)
    objMail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    
    objMail.Configuration.Fields.Update
    ----- End of SMTP usage ----->8---
    
    objMail.Send
    
    Set objMail=Nothing
    Wscript.Quit
    

    Update: found more info there: VBScript To Send Email Using CDO By default it seems it uses Outlook [Express], so it didn't worked on my computer but you can use a given SMTP server, which worked fine for me.

    0 讨论(0)
提交回复
热议问题