0

I am wondering if it's possible to run a job automatically in SQL Server when an email with specific subject is received on Outlook, so that I don't need to go through all my mails everyday and run the job manually.

I have googled this topic but most of articles were about sending an email from SQL Server when the job is finished for example.

Has anyone done this before and can guide me, please? If there is a way to do this.

Thank you.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
JuniorDev
  • 433
  • 3
  • 14
  • 30
  • 1
    Yes. It's possible. [You write a VBA macro that will execute when new items are received, you will test that item to see if it's a Mail type](https://stackoverflow.com/questions/11263483/how-do-i-trigger-a-macro-to-run-after-a-new-mail-is-received-in-outlook), then you test the subject to see if it matches whatever your criteria is, then you can [use ADODB to open a connection to your sql server and execute the job](https://stackoverflow.com/questions/11137302/excel-vba-executing-a-job-within-sql-server-via-a-macro).. Please come back here with a new question if you get stuck along the way. – JNevill Sep 14 '17 at 17:56

2 Answers2

0

OR You can use a more current technology by writing an add-in for Outlook.

Doyle
  • 81
  • 7
0

Python

You can use Python to scan Inbox for new emails and then execute SQL query against SQLServer.

Example

Here's the example how to filter all emails by specific word in email subject.

    outlook = win32com.client.Dispatch("Outlook.Application")
    namespace = outlook.GetNamespace("MAPI")
    root_folder = namespace.Folders.Item(1)
    inbox = root_folder.Folders[1]
    misc = inbox.Folders[0]
    conn=connect(connStr)
    cur=conn.cursor()
    for message in misc.Items:
        stats={}
        if message.Subject.startswith('[PROD] IQ->Snowflake'):
            stmt="Your SQL Server payload here"
            cur.execute(stmt)
Alex B
  • 2,165
  • 2
  • 27
  • 37