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.Ap plication" )
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
refers to the outlook object , like :
set out=WScript.CreateObject("
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
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(o lMailItem)
'Set properties for the mail item and send mail
With objMail
.To = "myemail@mymail.com;myemai l2@yahoo.c om"
.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
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
'Login to Outlook
objNameSpace.Logon
'Set the mail item
Set objMail = objOutlookApp.CreateItem(o
'Set properties for the mail item and send mail
With objMail
.To = "myemail@mymail.com;myemai
.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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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("Outl ook.Applic ation")
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.
here is the .vbs file content
I copy it from sjpedro
==========================
Set Out = wscript.createobject("Outl
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)
The link posted work with any COM app (which VBScript is too)
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.
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.
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.
Dim ws As Object
Set ws = CreateObject("wscript.shel
ws.run "mailto:someone@somewhere.