PDA

View Full Version : Outlook Solution Wanted



Castiel
11-24-2016, 09:16 AM
Hi

Upon pressing the SEND button, in case a specific email is not present in the TO field and base on the subject line of the email,I would like to be alerted by a window similar to the one that pops up on the screen when the user mentions attachement in the body of the email, but forgets to add it.

Unfortunately Outlook does not provide a rule that can be set for that purpose.

Can someone be so kind to post a VBA module or another solution for this issue?

Thank you in advace for your help.

gmayor
11-24-2016, 10:37 PM
You will have to explain "in case a specific email is not present in the TO field and base on the subject line of the email"

Castiel
11-25-2016, 02:37 AM
The process:

1. You compose the email
2. Subject line will always start with Sales Order
3. Press Send
4. If user forgets to add a specific email in the TO field, say "example at example.com", a window warning pops up telling the user that the example at example.com email is missing.

Help, please.

gmayor
11-25-2016, 05:52 AM
OK, the fog is clearing. If you press Send and there is no recipient you will always get a warning. You can't send a message without a recipient.
Do I take it that when you have Sales Order in the Subject that you wish to check the recipients to ensure that an e-mail address is included among those recipients? In that case, put the following in the ThisOutlookSession module.

Option Explicit

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
'Graham Mayor - http://www.gmayor.com - Last updated - 25/11/2016
Dim oRecipient As Recipient
Dim bName As Boolean
Const strAddress As String = "someone@somewhere.com" 'The address you wish to check
If InStr(1, Item.subject, "Sales Order") = 1 Then
For Each oRecipient In Item.Recipients
If oRecipient.Address = strAddress Then
bName = True
Exit For
End If
Next oRecipient
If bName = False Then
If MsgBox("The recipient '" & strAddress & "' is missing from the message." & vbCr & _
"Do you wish to send the message?", vbYesNo) = vbNo Then Cancel = True
'or just add the address e.g.
'Item.Recipients.Add(strAddress).Type = 2 'as CC (1 for To, 3 for BCC)
'Item.Recipients.ResolveAll
End If
End If
lbl_Exit:
Set oRecipient = Nothing
Exit Sub
End Sub

Castiel
11-25-2016, 06:31 AM
Hi

17692

Thank you for your reply and efforts.
I inserted that module as instructed - I suppose I did - but nothing happens when I send the emails.
I am using Outlook 2016.
I pressed Alt + F11 to open the Microsoft Visual Basic for Applications - VbaProject.OTM, doubled click ThisOutlookSession and pasted the code, pressed save, closed that window, and back to Outlook.
Then I composed and sent a message to test the code, nothing happens. I may be doing something wrong...

Castiel
11-25-2016, 06:52 AM
Hi
Sorry... it is actualy working...
Just some more details on that issue...
I should have mentioned that Outlook is being used by Quickbooks to send the Sales Orders.
The code does work as is. However, when I tested it by sending a Sales Order from Quickbooks, it does not work.
Also, the subject line starts with Sales Order, but it is actualy something like Sales Order SO10949 from [company name]. And that S010949 is the sales order number, which changes for every new sales order.

Castiel
11-25-2016, 06:59 AM
Also, the reason I need this reminder is because I do not email the sales order to the customer.
So, when I press email sales order from withing Quickbooks, Outlook picks up the default customer email, and not the one I usually use to email the sales orders.
I can't change that email, because I need it there to email other documents to our customers like their invoices, etc. Otherwise, I could just put down the email I usually use to email the sales orders... see my predictament?

gmayor
11-25-2016, 10:01 PM
I regret I know nothing about Quickbooks or how it interfaces with Outlook.

Castiel
11-28-2016, 02:02 AM
The relationship between Quickbooks and Outlook is this: Quickbooks uses Outlook as the default email client.

Castiel
11-28-2016, 02:05 AM
I regret I know nothing about Quickbooks or how it interfaces with Outlook.

Can this code be modified in order to be trigger the pop up warning windows if the following words are found in the body of the email?

cat:masterlink
cat:md
cat:lg
cat:hja