Excel VBA email loop - server connectivity error handling - excel

I have an automated Excel VBA loop which sends out a couple hundred e-mails daily over Outlook with a couple second intervals. Running this in Windows 10 + Office 365 environment.
While it runs fine in general, it crashes at times with error message We can't complete this because we can't contact the server right now. Please try again later
Internet connectivity is generally OK, but can't rule out a brief disturbance. It happens once every 1-2 weeks during the loop, but is an annoyance as it stops the automation. Email syntax is what I see as quite typical practice in Excel VBA -> Outlook email (stripped down version):
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.Display
.To = Range("Array_emp_email")
.SentOnBehalfOfName = "mailbox#domain.com"
.Subject = "mySubject"
.HTMLBody = "mailBody" & Signature
.Attachments.Add docPath & ".pdf"
.Send
End With
Set OutMail = Nothing
Set OutApp = Nothing
I'm stopped at Set OutMail before a new Outlook mail item should be opened.
When I press Debug and then Run/Continue, it always runs on, without exception, so making it programmatically try this line again, might be a possible solution? Do you guys have any suggestion on what would be a good practice to handle it?
Using plain On Error Resume Next and leave one e-mail unsent is not an option. Leaving e-mail unsent, but logging an error through On Error GoTo ErrHandler and closing the sub is something I could do myself, but that's less than ideal also, since it's an hassle to compile the same email again.
Ideally it would be "take a minute and try again" approach, but are there any good practices or code examples how to do that here?

If you are using online (as opposed to cached) in Outlook, it is guaranteed you will run into issues are this - network errors are unavoidable and must be expected.
You need to either turn the cached mode on (Outlook will deal with any network errors when it syncs your changes) or you need handle the error and retry later (seconds? minutes?).

Outlook provides two basic connectivity modes when you are connected to Exchange Server: Cached Exchange Mode and Online Mode.
Cached Exchange Mode gives users a seamless online and offline Outlook experience by caching the user's mailbox and the Offline Address Book (OAB) locally. With Cached Exchange Mode, which is the default setting for users, Outlook no longer depends on continuous network connectivity for access to user information. When a user is connected, Outlook continuously updates users' mailboxes so that the mailboxes are kept up to date. If a user disconnects from the network, for example, by moving to an area without Wi-Fi access, the user can continue to access the last available email data.
Online Mode works by using information directly from the server, and, as the name implies, it requires a connection. Mailbox data is only cached in memory and never written to disk. So, if you have connection problems with Exchange in the online mode, you may get such errors. I'd suggest enabling the cached mode to avoid any issues with a connection, see Turn on Cached Exchange Mode for more information.
Microsoft recommends always using Cached Exchange Mode with a Microsoft 365 account.

Related

Send Email outlook using Excel VBA

I am trying to send an email using Excel with this code :
Sub SEND_EMAIL()
Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")
Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)
' ADRESSE
olMail.To = "selojo7915#rippb.com"
' Subject
olMail.subject = "Line"
' BODY
olMail.body = "this"
olMail.Send
When starting this macro i have the following error
The error is in the last line (olMail.Send)
And every time i am trying to send an email outlook is starting to update and after a moment it's showing error
Exception de HRESULT : 0x80004004 (E_ABORT)
You see a security issue (earlier prompts) because Outlook is configured on the client computer in one of the following ways:
Uses the default Outlook security settings (that is, no Group Policy set up)
Uses security settings defined by Group Policy but does not have programmatic access policy applied
Uses security settings defined by Group Policy which is set to warn when the antivirus software is inactive or out of date
You can create a group policy to prevent security prompts from displaying if any up-to-date antivirus software is installed on the system or just turn these warning off (which is not really recommended).
Read more about that in the Security Behavior of the Outlook Object Model article.
You may consider using the following workarounds:
Install any antivirus software with latest updates.
Use a low-level API - Extended MAPI which doesn't trigger security issues. You may also consider Redemption which is a convenient wrapper around Extended MAPI.
Create a COM add-in which has access to the safe Application instance.
Use group policy settings to turn such security prompts/issues when dealing with Outlook.
Also you may consider using third-party components that allow turning off and on dynamically security prompts and issues in Outlook. See Outlook Security Manager for more information.

Acumatica - Outlook PlugIn Reply Action

we are using Acumatica outlook plugin to create CASES and we are successful in achieving it.
As you know outlook plugin will automatically create a email activity when we create case. So sometimes we send reply from Outlook plugin and some times we send reply from Acumatica.
The issue is - When we send reply from outlook plugin we are unable to see email in "All Emails" screen, but if we are sending reply to same case from Acumatica we are able to see email in "All Emails" screen.
Can someone please suggest us, what we are missing here.
We are in 2019R2, without any customization published.
There could be a couple of reasons you may be running into this problem. Depending on how you have your setup, one reason could be because of the way you have your System Email Account set up. Check what email is sending as, it could be sending a centralized account. Also check what you default email is set on your account.
Also, are you using the Outgoing Tab? Or looking looking at the all records tab? It could be because of the status of your email. When sending through the Outlook plugin, double check the emails are sending, and double check the status of the activity. It could not be completing and being left as an open item.

Outlook add-in check inline reply mode

I was forwarded to stackoverflow for questions.
I have created an addin for outlook that i want to publish on Add-ins store.
I have received failures on my application that i need to resolve.
When the user has made the action in my add-in. I close the email with
"Office.context.mailbox.item.close()"
https://learn.microsoft.com/en-us/javascript/api/outlook/office.messagecompose?view=outlook-js-1.5#close--
When using Outlook Desktop and replying with "inline reply mode" this method does not work. Is there a way to check if the mail is in "inline reply mode" or not?
I have made a image to be shown that the process is finished and i hope this works since closing the taskpane does not work.
As you noted above, Office.context.mailbox.item.close() does not work for inline replies in the desktop Outlook client. Unfortunately, we have no way of checking whether the email is in inline reply mode or not. We have a UserVoice page where we track feature requests. Please don't to add a feature request there. Feature requests on user-voice are considered, when we go through our planning process.

Run Outlook Macro when sending mail from Excel

I have a VBA code in Thisoutlooksession that runs when new mail is sent.
But when I send a mail using Excel biltin option to send the file attached, the code in the outlook don't run.
Would appreciate youre help.
Thanks in advance.
This is a situation where some Outlook functionality is not applied.
"You use Send As or other Send commands from another Microsoft Office application, such as Microsoft Word, Microsoft Excel, or Microsoft PowerPoint. This scenario typically occurs when you use a command to send the current file as an attachment." Messages that are created outside Outlook do not include the default Outlook email signature
"If you need all features to be available, you either need to create the email from Outlook itself or create the new email programmatically from within that other application as well." Outlook UserForms dont work when emailing from another application
"This is by design: messages created and sent by Simple MAPI or mailto url do not trigger OOM events. This is done on purpose - there were some problems in those scenarios, so events were completely disabled." ItemSend event is not firing

Excel Auto Send Emails via Outlook Randomly NOT Sending

I've inherited development of an Excel userform which contains a send button to return the user's data back to a central mailbox. The tool has just been rolled out to a larger community and some users are experiencing emails not being sent. These are random events as the users can sometimes send the forms and it is not form specific.
The tool uses the following code to create the email:
Set ObjOL = CreateObject("Outlook.Application")
Set ObjOutMail = ObjOL.CreateItem(0)
and is sent via:
ObjOutMail.send
We had tested this with a number of users and never had any problems, but we now have a number of users who have successfully sent 1 or more forms but 1 or more have also failed, and they also can't resend the successful forms any more either.
There are no error messages, the Outlook "this could be a virus, etc." confirmation is fired as usual (we have not attempted to circumvent this) but there is nothing in the 'Sent Items'. The users are also able to send conventionally generated emails so there is no mailbox limitations going on.
The Userform is modal and upon sending copies the three user fields to "Sheet1", saves itself and mails itself.
Really at a loss to understand what's going on.
Thanks for any advice.
EDIT: To add we are still using Office 2003 on Win XP.
Thanks for all the replies, using the .display property showed me what was up.
The email is addressed to what I thought was an explicit address, however there is an extra '(MULTIUSER)' post fix which I didn;t realise was actually part of the address, DOH!.
Last week and similar mailbox made up of the same address but with a different postfix was added to the system. This ment Outlook couldn't resolve the address and didn't send the emails.
Thanks again.

Resources