---
title: "Sending Email Notifications When Aria2 Downloads Complete"
description: "Configure automatic email notifications after Aria2 downloads complete, sending notifications that include the file path and system information via sendmail and a custom script."
canonical_url: https://ro.yikzero.com/en/blog/aria2-1/
locale: en
date: 2020-02-09
---

# Sending Email Notifications When Aria2 Downloads Complete

## Preface

Since I don’t really have any coding background and have never studied anything related to code, some of my descriptions may not be very accurate. I thought of this script while downloading movies. Nowadays, everything in society is becoming intelligent, so I also wanted to tinker around and make an email download notification.

## Screenshot

![Email Screenshot](https://cdn.yikzero.com/markdown/images/202311050924340.png)

## Setting Up the Email System

I ran into quite a few problems during installation and debugging, but after searching around and following this blogger’s [operation record](https://www.cnblogs.com/kevingrace/p/6143977.html), together with Baota, it can generally be configured successfully. Just test it a few more times yourself.

## Finding and Modifying the Script

I first found a notification script modified by the original poster on the [Enshan Wireless Forum](https://www.right.com.cn/forum/thread-163098-1-1.html).

In the script provided by that author, things like the email address just need to be filled in. However, at the time, I had some issues with the `sendmail` command, so I followed the records in the first section. Some of the script-related things had already been written into my server, so I changed a lot of the original script.

When I was debugging with the author’s script, the `aria2.log` kept showing the problem `no such file or directory`, but I couldn’t find the cause. Then I thought I would write the entire script using `pipes`... It seems a bit clumsy... but I didn’t know any other method.

```shell
echo "

文件路径：$3

完成时间 `date +%Y/%m/%d`  `date +%T`

负载 "`uptime`"

版本 "`uname -a`"

From Zero.

Have a nice day." | mail -s 'Aria2通知' example@qq.com
```

This is the content of my script. It’s very simple, right... But it actually took me a long time to make something usable. `Aria2通知` is the email subject. The specific meanings of the parameters should all be found in the article link in the first section.

## Final Debugging

Specific steps:

1. Upload the `email.sh` script to the server
2. Modify the `on-download-complete=` parameter in `aria2.conf`; after `=`, fill in the script’s `absolute path`

In order to achieve both:

- Email notification
- Automatic upload

I call `email.sh` from the `autoupload.sh` script

Specific writing:

```shell
. /root/.aria2/email.sh
```

My `Aria2` uses the [Aria2 One-Click Installation Management Script](https://github.com/P3TERX/aria2.sh)

## Conclusion

I’m not very satisfied with this script myself. Although it can implement the basic functions, it has the following **problems**

1. One download will send two emails: one email when the torrent download completes, and one email when the file download completes.
2. I don’t understand the syntax. I tried things like `basename` and `##/`, but after trying for quite a while, I still couldn’t successfully get the filename.

**This is my first time writing an article. I don’t know anything about formatting, and it’s also quite wordy. But it was pretty fun.**