Link to home
Start Free TrialLog in
Avatar of Michel Sakr
Michel SakrFlag for Canada

asked on

Sending E-mail in VBS (SMTP)

Hello I need to know if there is a way to send e-mail thru VBS to SMTP(like CDONTs ) My script is not processed thru ASP, the VB script will run on the same machine... I need @ least 2 examples 1 to SMTP and one thru outlook with working codes for an NT 4.0 server box(no 3rd parties soft) that's why I gave it 222 pnts
TNX..
Avatar of manikantan
manikantan

Hi...
Can U Be Clear...
U need a mailing Component For a Standalone Vb application Or For A Server Side Vb App(ASP)

Tell Me..
Regards
Manikantan
Avatar of Michel Sakr

ASKER

Hi mani..
If you read between the lines, I said "My script is not processed thru ASP.." It's a VBscript (VBS file)
rgrds
There Are Lots of Other Components Like The Abmailer ,Jmailer and Essmtp ...
I don't have the components but i have the code to operate Them except for essmtp for which i have code and component...
Regards
Manikantan
This little snippet is from my VBS file:

'get recipients from address book
Set o = New Outlook.Application
Set n = o.GetNamespace("MAPI")
Set v = o.CreateItem(olMailItem)
v.AddRecipient "blah"
v.save
v.send
v.whatever you want to do
I didn't mention that the process must be automated.. without profile promptings etc.. (using MAPI)
Just a heads up, but Outlook was never designed to run from a service.  If no prompting for a profile and running from VBS is one of your requirements, then you would want to use Collaboration Data Objects (CDO)*.

--- BEGIN VB Example ---
Sub Main()
      ' How to write a Visual Basic Active Messaging App that can be run
      ' from the Windows NT Schedule Service.
      ' ----------------------------------------------------------------
      ' To demonstrate this functionality, the Schedule Service MUST be
      ' run in the context of a USER ACCOUNT (not the system account.)
      ' To set the Schedule Service Context:
      '   - From the Control Panel select the Services icon
      '   - Scroll down and single click the Schedule Service
      '   - Single click the Startup button
      '   - Select "This Account", and enter YOURDOMAIN\YOURACCOUNT
      '   - It is also suggested that Startup be Manual
      '
      ' With this done, choose the Start button (you should see a dialog box
      ' indicating success). Close the Control Panel.
      '
      ' Now you need to schedule the application to execute. To do this:
      '   - From the Start Menu choose Run
      '   - At the prompt, enter "AT HH:MM PATH\MYEXE.EXE" where
      '   * HH:MM is the time the application is to execute. This is a 24
      '   hour clock, and time is based on the system clock.
      '   * PATH\MYEXE.EXE is path and filename of your EXE.
      '
      SendScheduledMsg
End Sub
 
Sub SendScheduledMsg()
      'Setup variables for use
      Dim objSession As MAPI.Session
      Dim objMsg As Message
      Dim objRecip As Recipient
 
       'Create Session and Logon
      Set objSession = CreateObject("mapi.session")
      objSession.Logon _
            nomail:=True, _
            profileinfo:="YOURSERVER" & vbLf & "YOURMAILBOX"
 
       'Create new Message and set properties.
      Set objMsg = _
       objSession.Outbox.Messages.Add( _
         Subject:="This is a Message Sent From a Scheduled Service", _
         Text:="This is a test")
 
       'Add a Recipient.
       Set objRecip = objMsg.Recipients.Add(Name:="YourRecipsEmailName")
       objRecip.Resolve
 
       'Send the Message and Logoff.
      objMsg.Send
      objSession.Logoff
 
       'Cleanup
      Set objRecip = Nothing
      Set objMsg = Nothing
      Set objSession = Nothing
End Sub
 
--- END VB EXAMPLE ---

Note: To use from VBScript, you would have to change the explicit DIM statements to just DIM somevariable.


*The CDO library comes with Outlook 98 and Outlook 2000.
ASKER CERTIFIED SOLUTION
Avatar of Neo_mvps
Neo_mvps

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK neo, You got your 1000 points :+)
I am trying to do exactly that - but it doesn't work!!!

I am calling a vbs which creates a cdonts message just like your example (without the reply-to header), and it works when I run from the command line (logged on as an admin with a mailbox)

But when call it from an asp or from the AT scheduler it gives an error!

I use a Win2k server (SBS2000)

I can't work out what account it is trying to send from when called from asp (with authentication) or from AT (Service?)

I read of an exchange 2000 SP3 mod which causes problems - I want to add the account used by the asp to send
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q324037
How do I work out the account used to run the winshell wscript myscript.vbs command from the asp
???
Have you guys got any idea?
Yusuf(info@bias.net)
AT (Task Schedular) runs under the local system.  AFAIK, the steps in workaround 3 in 324037 should work for scripts that are running from the task schedular.


As for IIS/ASP, open up the IIS manager and bring up the properties on the computer object.  Go to directory security and then select edit under anonymous access.  IIS is using this account.