2
votes

I need to send a very simple email with only text to a few recipients, but I'm getting an error.

I don't have an SMTP server to send emails through, but I do have an outlook and I'm logged in through the desktop app.

Here's the script so far:

Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
objMail.Display 

objMail.to = "[email protected]"
objMail.Subject = "Test"
objMail.Body = "test"

objMail.Send

objOutlook.Quit

Set objMail = Nothing
Set objOutlook = Nothing

When the script is run, WSH gives the error

line: 10 
char:  1 
error: Operation Aborted 
source: (null)

This is the objMail.Send line.

And my outlook pops up with the proper recipient/subject/body, but it doesn't send. I can't find anything related to this issue or a work around besides using an SMTP server which as far as I know I can't do.

2
Let me know if it worked for you...0m3r
Sorry about not responding. I found out that there was a firewall issue causing emails to not be sent. My script works now.Ausche

2 Answers

1
votes

I have a function defined and in daily use which accepts the various items for creating and sending the email. Remember if you have to create your Outlook instance, you need to log on with the appropriate mail profile in order to send anything. The profile we use here is just called "Outlook". Check what yours is called and include the Namespace stuff I have in mine.

Dim sComputer : sComputer = "." ' selects local machine
Dim oWMIService : Set oWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2")
Dim colItems : Set colItems = oWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'outlook.exe'")
Dim oOutlook : Set oOutlook = CreateObject("Outlook.Application")
Dim oNamespace : Set oNamespace = oOutlook.GetNamespace("MAPI")
If colItems.Count = 0 Then
    LOG_Write "Outlook isn't open, logging onto it..."
    oNamespace.Logon "Outlook",,False,True ' name of Outlook profile
    bOpenedOutlook = True
End If
Dim oFolder : Set oFolder = oNamespace.GetDefaultFolder(olFolderInbox)
oFolder.Display ' Make Outlook visible
0
votes

Here is basic vbscript simple email

' For Example...
Email_List = "[email protected];"

Set App = CreateObject("Outlook.Application")
Set Mail = App.CreateItem(0)

With Mail
    .To = Email_List
    .CC = ""
    .BCC = ""
    .Subject = "Hello World"
    .HTMLBody = "Bla Bla!!!"
    '.Body = strbody
    'You can add a file like this
'                .Attachments.Add (FilePath)

    'use .Send (to send) or .Display (to display the email and edit before sending)
    .Display
    .send
End With

Set Mail = Nothing
Set App = Nothing

Save is as name.vbs