How to be reminded that the Linux email has been sent?

In Linux, you can use command line tools like mail or sendmail to send emails. These tools do not provide email sending reminders by default, but you can use scripts or scheduled tasks to set up email reminders.

Here’s an example of using a script to send email reminders.

  1. reminder email script
$ touch sendmail_reminder.sh
$ chmod +x sendmail_reminder.sh
  1. Edit the script file and add the following content:
#!/bin/bash

# 发送邮件提醒函数
sendmail_reminder() {
    # 判断最近一次邮件发送的时间
    last_sent=$(stat -c %Y /var/mail/your_username)
    current_time=$(date +%s)
    time_diff=$((current_time - last_sent))

    # 如果时间间隔超过设定的阈值,则发送提醒邮件
    if [ $time_diff -gt 3600 ]; then
        echo "请检查您的邮件,您已经超过一个小时没有收到新邮件了!" | mail -s "邮件提醒" your_email@example.com
    fi
}

# 调用邮件提醒函数
sendmail_reminder

Please remember to replace your_username with your username, and your_email@example.com with your email address.

  1. Save the script file and exit the editor.
  2. To schedule a task to run regularly and send email reminders, use the crontab command. For example, to run the script every hour, you can use the following command.
$ crontab -e

Add the following content in the open editor:

0 * * * * /path/to/sendmail_reminder.sh

Please replace /path/to/sendmail_reminder.sh with the actual script file path.

  1. Save the scheduled task and exit the editor. This will ensure the email alert script runs every hour.

By following these steps, you can set up a scheduled task to regularly check the time of the latest email sent and send a reminder email to your inbox. If you haven’t received any new emails after a set amount of time, you will receive a reminder email.

广告
Closing in 10 seconds
bannerAds