自动化graph.microsoft.com身份验证和邮箱读取

时间:2019-01-14 17:47:24

标签: bash oauth-2.0 outlook

我正在尝试调试bsp脚本,该脚本可以由Splunk运行以登录到Outlook.com并阅读收件箱中的电子邮件。

我已经创建了bash脚本并通过手动运行每一行来测试每个部分。

#!/bin/bash
#

#
# Get the mailbox name
#
MAILBOX=$1

#
# Verify the mailbox name
#
case $MAILBOX in
    "mine")
         ;;
    "work1")
         ;;
    "work2")
         ;;
    "work3")
         ;;
    *)
         echo "$1 is not a valid mailbox."
         exit 1
         ;;
esac

#
# Set Globals
#
SLEEP_TIME=600

#
# Export the libraries needed for SSL
#
export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64

#
# Set the paths
#
BIN_DIR=/home/splunk/bin
MY_MESSAGES=/apps/data/monitored_mailboxes/${1}

#
# Change directory to where $MY_MESSAGES are
#
cd $MY_MESSAGES

#
# Copy last_read.txt to a back up file and set last_read.txt to the far future so it only sets the token
#
mv last_read.txt last_read_backup.txt
echo "2100-01-01 00:00:00+0000" > last_read.txt

#
# Get the token
#
python ${BIN_DIR}/get_inbox_email.py -l ${MY_MESSAGES}/last_read.txt -t ${MY_MESSAGES}/0365_token.txt

#
# Restore the original last_read.txt
#
mv last_read_backup.txt last_read.txt

#
# Loop the python script
#
while true; do
  #
  # Get the current timestamp
  #
  timestamp=`date +'%Y-%m-%d_%H:%M:%S'`

  #
  # Get the messages if any
  #
  python ${BIN_DIR}/get_inbox_email.py -l ${MY_MESSAGES}/last_read.txt -t ${MY_MESSAGES}/0365_token.txt > ${MY_MESSAGES}/messages/mail_${timestamp}.txt

  #
  # Remove old message files
  #
  find ${MY_MESSAGES}/messages -mtime +7 -print

  #
  # Sleep
  #
  sleep $SLEEP_TIME
done

我希望第二个python调用使用在第一个python调用中创建的令牌,但是系统提示我再次打开身份验证URL,然后粘贴到电子邮件URL中。

1 个答案:

答案 0 :(得分:0)

老疲倦的眼睛。我有0365_token.txt而不是o365_token.txt。当我在bash脚本中替换掉它时,我能够开始运行它而没有任何问题。

相关问题