outlook automation

iknowu99

Well-known Member
Joined
Dec 26, 2004
Messages
1,158
Office Version
  1. 2016
i would like to respond to specific emails automatically right away.

so if fakeJayfake@fakegmail.com sends me an email, respond right away with "Hi Jay right now is " & time.

Something simple like so. Thanks World:)
 
Last edited by a moderator:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Thanks Smitty!

I've actually made the following, only can't figure out how to check whether the message is new or not?? for now it goes through all the emails in the inbox


Code:
Option Explicit

Private Sub Application_NewMail()
DoEvents
Call UPDATEMYMAIL
End Sub

Sub UPDATEMYMAIL()
Dim oNS As NameSpace
Dim oFL As Outlook.MAPIFolder
Dim oMI As MailItem
Dim strABC As String

Dim oNewMail As Object

Set oNS = Outlook.GetNamespace("MAPI")
Set oFL = oNS.Folders("Mailbox - Michael").Folders("Inbox")



For Each oMI In oFL.Items

'## here test whether the email is new - but how ??

'strABC = oMI.ReceivedTime
strSenderEmailAddress = oMI.SenderEmailAddress

    If strSenderEmailAddress = "michaelTEST@gmail.com" Then
    
        If InStr(oMI.Body, "est") > 0 Then
        
        'Create a Reply template
            Set oNewMail = oMI.ReplyAll
            
            With oNewMail
                
                'Change the subject
                .Subject = oNewMail.Subject
                
                'Change the body
                .Body = "Michael got it. Thanks."
                .Send
            
            End With
        
        End If
    
    'ElseIf strSenderEmailAddress = blank2 Then
    
    'ElseIf strSenderEmailAddress = blank2 Then
    
    Else
    
    End If
    
Next oMI

Set oFL = Nothing
Set oNS = Nothing
End Sub
 
Upvote 0
Sorry, it's been years since I did any Outlook programming. Have you checked Ron DeBruin's site? He's the Outlook guy.
 
Upvote 0
I believe you can use the GetLast method to find the last email in the folder.

Code:
Set oMI = oFL.Items.GetLast

So the above should assign the mail item variable oMI to be the last email received in the predefined folder.

You can then dispose of the For Each loop and just work with oMI.
 
Last edited:
Upvote 0
that last part is not doing it: for some reason it depends on how the mails are sorted and usually takes the last one from the bottom. Perhaps theres a way to identify emails that have not been read, and read them with this macro. afterwhich mark them 'read' status?
 
Upvote 0

Forum statistics

Threads
1,225,381
Messages
6,184,632
Members
453,248
Latest member
gmazee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top