Link to home
Start Free TrialLog in
Avatar of Sam80
Sam80

asked on

How to send an email with a vb script file?

I want to use a script file to send an email , initially , i think this
refers to the outlook object , like :
 
set out=WScript.CreateObject("Outlook.Application")
set Mymail=out.CreateItem(0)
Mymail.to="abc@yahoo.com"
Mymail.Subject = "hihi"
Mymail.body="hello"
Mymail.send
set Mymail=Nothing
Set out=Nothing

but it seems there is no mail has been sent , why ? any suggestion?

My outlook version is 6.0, os is ms2000 server
Avatar of Richie_Simonetti
Richie_Simonetti
Flag of Argentina image

did you tried?

Dim ws As Object
Set ws = CreateObject("wscript.shell")
ws.run "mailto:someone@somewhere.com?subject='Some kind of text...'"
Avatar of Sam80
Sam80

ASKER

In fact, to the user ,I want to send a mail in a transparent mode , not display a outlook form to send a mail.

Hi -

This code works from VB and it does not display outlook form to send e-mail.
I don't think is what you looking for, but it might give you ideas about how to generate a script.


Private Sub Form_Load()
      Dim objOutlookApp As Outlook.Application
      Dim objNameSpace As Outlook.NameSpace
      Dim objMail As Outlook.MailItem
 
      'Set the application objects
      Set objOutlookApp = Outlook.Application
      Set objNameSpace = objOutlookApp.GetNamespace("MAPI")
 
      'Login to Outlook
      objNameSpace.Logon
 
      'Set the mail item
      Set objMail = objOutlookApp.CreateItem(olMailItem)
 
      'Set properties for the mail item and send mail
      With objMail
             .To = "myemail@mymail.com;myemail2@yahoo.com"
             .Subject = "Message Sent from Visual Basic"
             .Body = "This is a test from VB!"
             .Send
      End With
 
      'Logoff NameSpace
      objNameSpace.Logoff
 
      'Release objects
      Set objMail = Nothing
      Set objNameSpace = Nothing
      Set objOutlookApp = Nothing
    Unload Me
   
End Sub

ASKER CERTIFIED SOLUTION
Avatar of Richie_Simonetti
Richie_Simonetti
Flag of Argentina image

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
Avatar of Sam80

ASKER

Thank you guys , but it doesn't work in VB script

here is the .vbs file content
I copy it from sjpedro
=============================
     Set Out = wscript.createobject("Outlook.Application")
     Set objNameSpace = Out.GetNamespace("MAPI")
     objNameSpace.Logon
     Set objMail = Out.CreateItem(olMailItem)

     With objMail
            .To = "mail@mail.com"
            .Subject = "Message Sent from Visual Basic"
            .Body = "This is a test from VB!"
            .Send
     End With

     
     objNameSpace.Logoff

     Set objMail = Nothing
     Set objNameSpace = Nothing
     Set Out = Nothing
=============================

You save this code as .vbs file ,and test it.

please tell me any progress you have done in this function.
what is not work with vbscript?
The link posted work with any COM app (which VBScript is too)
Avatar of Sam80

ASKER

This script can not send a mail at all.
Like you said ,it can link to the COM app, with no error,
however, it can not send a mail.

"This script can not send a mail at all.
Like you said ,it can link to the COM app, with no error,
however, it can not send a mail."
Then, why did you accept my comment?
We could try to do it run properly. I used that with no problems.