?
Solved

How to send an email with a vb script file?

Posted on 2003-03-23
8
Medium Priority
?
171 Views
Last Modified: 2012-05-04
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
Comment
Question by:Sam80
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8191886
did you tried?

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

Author Comment

by:Sam80
ID: 8192983
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
 
LVL 1

Expert Comment

by:sjpedro
ID: 8193359
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
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!

 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 200 total points
ID: 8194860
0
 

Author Comment

by:Sam80
ID: 8196793
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8196870
what is not work with vbscript?
The link posted work with any COM app (which VBScript is too)
0
 

Author Comment

by:Sam80
ID: 8196906
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8234929
"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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question