How can I send an e-mail from a vbs script

2019-07-16 06:11发布

How can I send an e-mail from a vbs script - on a machine that cannot connect to the internet (it's in my non-internet zone).

I've hacked the following together from my googling, but is seems to require a call to Microsoft's server. What about the situation where I'm not able to reach microsoft.com?

sch = "http://schemas.microsoft.com/cdo/configuration/" 

Set cdoConfig = CreateObject("CDO.Configuration") 

With cdoConfig.Fields 
    .Item(sch & "sendusing") = 2 ''cdoSendUsingPort 
    .Item(sch & "smtpserver") = "my_internal_mail_server"
    .update 
End With 

Set objEmail = CreateObject("CDO.Message")
set objEmail.configuration = cdoConfig
objEmail.From = "me@example.com"
objEmail.To = "me@example.com"
objEmail.Subject = "Server is down!"
objEmail.Textbody = "Run out the guns!!!"
objEmail.Send

MsgBox "Script Complete"

(I have an internal SMTP server... the problem is having to poll the MS server)

3条回答
ゆ 、 Hurt°
2楼-- · 2019-07-16 06:39

You need a SMTP server that is accessible from where your script will run that knows how to send the email to where it needs to go. You can configure IIS or Exchange to do SMTP (or any number of open source projects), but it needs to be configured so it can relay the email to where it needs to go.

EDIT: I was under the impression that the schema was just a namespace for the configuration fields, not something that it actually tried to load from a microsoft server. When you run it, giving it your internal smtp server name, what happens? Do you get an error?

查看更多
We Are One
3楼-- · 2019-07-16 06:44

I'm in such a situation at work, we have only one SMTP server that can do mailing but have scripts all over the place who need to do mailing too. So i append the mail as a one line text string to a file on the SMTP server where a VBS script is scheduled that reads this file ands sends out the mails. If you're interested i publish it here tomorrow. Hope it helps..

查看更多
4楼-- · 2019-07-16 06:48

An alternative if you want quick and dirty is blat which is a command line utility for sending mail via SMTP. http://www.blat.net

查看更多
登录 后发表回答