0 votes
1 view
in RPA by (5.3k points)

I am developing a script to send an email according to certain inputs, I am able to craft the email but not send it using the .Send method.

I am getting the following error: (please note that the line is matching the .Send use in the original case)

enter image description here

I have already successfully sent emails using the .SendKeys(^~) method, but I would like to be use Outlook object to do so and not simply send shortcuts.

This is my current code:

This is my current code:

' Declare all variables that will be used later on Dim outobj, mailobj, emailto, cc, subject, body, attachement Dim strFileText Dim objFileToRead Dim splitEmailto ' Set the outlook application object Set outobj = CreateObject("Outlook.Application") ' set the namespace Set myNamespace = outobj.GetNameSpace("MAPI") msgbox myNamespace.Folders(2) ' Set the mail item object Set mailobj = outobj.CreateItem(olMailItem) ' Set a shell Set WshShell = WScript.CreateObject("WScript.shell") ' Get all the argument and assign emailto = "[email protected]" cc = "[email protected]" subject = "Simple Email" body = "Some Text" attachement = "C:\Users\name\Desktop\fileName.xls" ' Craft the email object With mailobj .Display ' assign the tos .To = cstr(emailto) ' add CCs .CC = cstr(cc) ' attach the relevant files If attachement <> "" Then If instr(attachement, ";") Then splitAtt = split(attachement, ";") For Each att In splitAtt If att <> "" Then .Attachments.add cstr(att) End If Next Else .Attachments.add cstr(attachement) End If End If If Subject <> "" Then .Subject = Subject ' sets the subject End If If body <> "" Then .Body = body ' sets the body End If .Send End With ' Clear the memory Set outobj = Nothing Set mailobj = Nothing ' check for no more events in the sending event ' Report out & Quits WScript.StdOut.WriteLine("Email sent") WScript.Quit

1 Answer

0 votes
by (9.5k points)

E_ABORT is the cause of error here,

You are processing as displaying the message and immediately calling Send

 You should  either display the message (Display, but no Send), or just send it out with displaying (Send, but no Display)

Related questions

0 votes
1 answer
asked Jul 10, 2019 in RPA by noah kapoor (5.3k points)
0 votes
1 answer
0 votes
0 answers
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...