Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

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
0
Sam80
Asked:
Sam80
  • 4
  • 3
1 Solution
 
Richie_SimonettiIT OperationsCommented:
did you tried?

Dim ws As Object
Set ws = CreateObject("wscript.shell")
ws.run "mailto:someone@somewhere.com?subject='Some kind of text...'"
0
 
Sam80Author Commented:
In fact, to the user ,I want to send a mail in a transparent mode , not display a outlook form to send a mail.

0
 
sjpedroCommented:
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

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Richie_SimonettiIT OperationsCommented:
0
 
Sam80Author Commented:
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.
0
 
Richie_SimonettiIT OperationsCommented:
what is not work with vbscript?
The link posted work with any COM app (which VBScript is too)
0
 
Sam80Author Commented:
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.

0
 
Richie_SimonettiIT OperationsCommented:
"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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now