Outlook 2010 Email Issue

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
jonesey10
Newbie
Posts: 8
Joined: Wed Mar 31, 2010 3:11 pm

Outlook 2010 Email Issue

Post by jonesey10 » Wed Jun 29, 2011 1:24 pm

Hi everyone,

I've used this code for over a year, but recently upgraded to Office 2010 and I'm having issues with this code. It will work when I already have outlook opened on my computer, but if outlook isn't opened I get this error: ":-2147467260 Line 25, Column 0" Any help would be greatly appreciated. The code is below:

VBStart

Function CreateEmail(strRecipient, strSubject, strBody)
'Create OL App object
Set objOLApp = CreateObject("Outlook.Application")

If objOLApp is nothing then
MsgBox "Could not create OL App. Shutting Down"
Exit Function
End If

'Create a new mail item
Set objMsg = objOLApp.CreateItem(0)
If objMsg is nothing then
MsgBox "Could not create Mail Item. Shutting Down"
Exit Function
End If

'Set basic message parameters
objMsg.To = strRecipient
objMsg.Subject = strSubject
objMsg.Body = strBody

'Send the message
objMsg.Send

'Free up the space
Set objOLApp = Nothing
Set objMsg = Nothing

CreateEmail = "Success"
End Function


VBEnd

Let>strTo=distributionlist
vbe>date()-1,mydate
Let>strSubj=Daily Sales: %mydate%
Let>body=
Let>k=1
Label>start
ReadLn>c:\sales.txt,k,line
If>line=##EOF##,finish
Let>body=%body%%CRLF%%line%
Let>k=k+1
Goto>start
Label>finish
StringReplace>body,CRLF," & vbCRLF & ",body

VBEval>CreateEmail("%strTo%","%strSubj%","%body%"),Answer

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Wed Jun 29, 2011 2:07 pm

Have you tried the SMTPSendMail command?

Doing it with the built-in Macro Scheduler command would mean
that you are no longer dependent upon Outlook even being installed
, let alone running on your computer.

Code: Select all

SMTPSendMail

SMTPSendMail>recipients,server,from_address,from_name,subject,body,attachments

Sends email via an SMTP server to the recipients entered.

recipients : Include one or more email addresses, separated by semicolons (;).

server : The name or IP address of your SMTP server.

from_address : Your email address, or the email address you want the message to come from.
from_name : Your real name, or a string to appear in the from name field.
subject : The subject line.
body : The body text of the message.
attachments : if sending files include each file separated by semicolons (;).  If no attachments end the line with a comma.

By default when this command is in use a small status window will appear at the top left of the screen.  You can stop this window being displayed by setting SENDMAIL_STATUS to 0.

To include CC or BCC email addresses set the SMTP_CCLIST and SMTP_BCCLIST variables.  Separate multiple email address with semicolons.

If you are using an SMTP server that requires authentication, you can enable authentication by setting SMTP_AUTH to 1, and then setting SMTP_USERID and SMTP_PASSWORD to the username and password that you need to connect to the SMTP server.  e.g:

Let>SMTP_AUTH=1
Let>SMTP_USERID=myuser
Let>SMTP_PASSWORD=frogslegs
To enable return receipt of the email, set SMTP_RECEIPT to 1.

By default the port used by SMTPSendMail is 25.  If you need to change the port number set the value of SMTP_PORT.

The result of the sendmail operation is placed into the variable SMTP_RESULT.  The format of this response depends on the SMTP server being communicated with.  If successful the value will contain the result code 250.  Otherwise it will contain the appropriate error message.

SMTP_TIMEOUT can be used to set a connection timeout in milliseconds.  This timeout relates to the initial connection to the SMTP server.

Abbreviation : SMT

See Also: RetrievePOP3

Example
Let>SENDMAIL_STATUS=1
Let>subject=Test Message
Let>[email protected]
Let>myname=Mr Smith
Let>[email protected];[email protected]
Input>body,Enter your message:
SMTPSendMail>recipients,post.mail.com,me,myname,subject,body,
Message>Result of SendMail: %SMTP_RESULT%
 

paulljucovic
Newbie
Posts: 1
Joined: Thu Sep 22, 2011 11:29 am

Post by paulljucovic » Thu Sep 22, 2011 12:52 pm

Hi,

I had the same issue. A lady that reported to me when I was working in our US office upgraded to office 2010 before me and she said that she needed to add 3 lines: (1) open office, (2) wait 5 seconds, (3) close office

The first line was at the top of the code, the last two were at the bottom. See my example below.

This worked for her, but she is now on maternity leave. I copied her code and I get an error in line 25 when it tries to "objMsg.send".

Anyone else have any thoughts? I like the way it worked (as opposed to using the idea from the first reply to this message) because it was intergrated with my Outlook Mail distribution list, which I use for may things. I know this can work, there's something very small stopping it.

Here is the code from lines 37 and on:

Run Program>C:\Program Files\Microsoft Office\Office14\Outlook.exe
Let>strTo=test
vbe>date()-1,mydate
Let>strSubj=Canada Retail Daily Sales Flash: %mydate%
Let>body=
Let>k=1
Label>start
ReadLn>R:\CanadaSite\Financial Models\Blackberry.txt,k,line
If>line=##EOF##,finish
Let>body=%body%%CRLF%%line%
Let>k=k+1
Goto>start
Label>finish
StringReplace>body,CRLF," & vbCRLF & ",body

VBEval>CreateEmail("%strTo%","%strSubj%","%body%"),Answer
wait>5
CloseWindow>Inbox - Mailbox - Ljucovic, Paul - Microsoft Outlook

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts