Sending emails via command line: Difference between revisions
Appearance
Fixed a missing space between the password and the recepient email in the example code |
No edit summary |
||
| (7 intermediate revisions by 5 users not shown) | |||
| Line 20: | Line 20: | ||
==Logging in to the router== | ==Logging in to the router== | ||
Once you have all the necessary email information, choose your | Once you have all the necessary email information, choose your favorite method of sending command line queries or the one that is currently available to you and log in to your router accordingly. The most common methods of doing so are '''[[CLI]]'''('''Command Line Interface''') and '''SSH'''. | ||
'''Note''': in further examples of this guide we will be demonstrating how to send email using SSH. Feel free to follow the guide step by step whichever method you choose, because the commands used are identical and the only thing that is different is the GUI (Graphical User Interface). | '''Note''': in further examples of this guide we will be demonstrating how to send email using SSH. Feel free to follow the guide step by step whichever method you choose, because the commands used are identical and the only thing that is different is the GUI (Graphical User Interface). | ||
===CLI=== | ===CLI=== | ||
---- | ---- | ||
* CLI can be reached through the router's WebUI. To reach the router's WebUI, simply enter the router's LAN IP address ('''192.168.1.1''' by default) into your browser's URL bar and press "Enter". Next, type in the router's login information (user name: '''admin'''; password: ''' | * CLI can be reached through the router's WebUI. To reach the router's WebUI, simply enter the router's LAN IP address ('''192.168.1.1''' by default) into your browser's URL bar and press "Enter". Next, type in the router's login information (user name: '''admin'''; password: '''<device password>''') and click "Login": | ||
[[File: | [[File:Rut_login_page_exampleV2.png|border|class=tlt-border]] | ||
---- | ---- | ||
*Next, navigate to the ''' | *Next, navigate to the '''System''' → '''Maintenance''' → '''CLI''' option from the drop-down list: | ||
[[File: | [[File:Send_email_via_cliV2.png|border|class=tlt-border]] | ||
---- | ---- | ||
* In the next window, type in the user name '''root''' and press "Enter". Then type in the router's password (same one you used for logging in to the router), press "Enter" and you should be greeted with a window such as this: | * In the next window, type in the user name '''root''' and press "Enter". Then type in the router's password (same one you used for logging in to the router), press "Enter" and you should be greeted with a window such as this: | ||
[[File: | [[File:CLI rutos v5.png|border|class=tlt-border]] | ||
Once this is done, you will able to execute commands via CLI. | Once this is done, you will able to execute commands via CLI. | ||
| Line 43: | Line 43: | ||
===SSH=== | ===SSH=== | ||
---- | ---- | ||
If you are using a Windows OS, you can use the free '''PuTTY''' app to login to a RUTxxx router via SSH; if you're using a Linux based OS, just use the '''Terminal''' app. In both cases you will need to know three things: the router's LAN IP address, user name and password. The default LAN IP address for all RUTxxx routers is '''192.168.1.1'''; the default login information is user name: '''root'''; password: ''' | If you are using a Windows OS, you can use the free '''PuTTY''' app to login to a RUTxxx router via SSH; if you're using a Linux based OS, just use the '''Terminal''' app. In both cases you will need to know three things: the router's LAN IP address, user name and password. The default LAN IP address for all RUTxxx routers is '''192.168.1.1'''; the default login information is user name: '''root'''; password: '''<device password>''' (NOTE: the user name used for SSH connections (i.e., root) is not the same as the user name used to login to the router's WebUI (i.e., admin)). | ||
---- | ---- | ||
* '''Linux''': open PuTTY; enter the router's LAN IP address into the '''Host Name (or IP address)''' field, specify '''port 22''', select SSH Connection type and click '''Open''': | * '''Linux''': open PuTTY; enter the router's LAN IP address into the '''Host Name (or IP address)''' field, specify '''port 22''', select SSH Connection type and click '''Open''': | ||
| Line 51: | Line 52: | ||
* In the next window type in the user name, press "Enter", type in the router's admin password and press "Enter" again. You should be greeted with a message such as this: | * In the next window type in the user name, press "Enter", type in the router's admin password and press "Enter" again. You should be greeted with a message such as this: | ||
[[File:Putty login | [[File:Putty login v3.png|alt=]] | ||
Once this is done, you will able to execute commands via SSH. | Once this is done, you will able to execute commands via SSH. | ||
| Line 57: | Line 58: | ||
* '''Linux''': open a new Terminal window, type '''ssh [email protected]''' and press "Enter". If this is your first time logging in, you might be asked to clarify whether you really want to login. In that case, just type '''yes''' and press "Enter". Then type in the router's admin password and press "Enter" to finish the login process: | * '''Linux''': open a new Terminal window, type '''ssh [email protected]''' and press "Enter". If this is your first time logging in, you might be asked to clarify whether you really want to login. In that case, just type '''yes''' and press "Enter". Then type in the router's admin password and press "Enter" to finish the login process: | ||
[[File: | [[File:SSH linux login v4.png|alt=]] | ||
Once this is done, you will able to execute commands via SSH. | Once this is done, you will able to execute commands via SSH. | ||
| Line 71: | Line 72: | ||
This method is useful when sending short emails. As an example, lets send an email containing the message "'''Hello, JustTesting'''", from the hypothetical address '''[email protected]''' to '''[email protected]''' using Gmail's SMTP settings: | This method is useful when sending short emails. As an example, lets send an email containing the message "'''Hello, JustTesting'''", from the hypothetical address '''[email protected]''' to '''[email protected]''' using Gmail's SMTP settings: | ||
:~# echo -e "subject:Test\nfrom:[email protected]\nHello,\n\nJustTesting" | sendmail -v -H "exec openssl s_client -quiet -connect smtp.gmail.com:587 - | :~# echo -e "subject:Test\nfrom:[email protected]\nHello,\n\nJustTesting" | sendmail -v -H "exec openssl s_client -quiet -connect smtp.gmail.com:587 -tls1_3 -starttls smtp" -f [email protected] -au"[email protected]" -ap"senders.email.password" [email protected] | ||
Let's examine this command in detail. First, this part: | Let's examine this command in detail. First, this part: | ||
| Line 92: | Line 93: | ||
So in short, the part beginning with '''echo''' and ending just before the column ('''|''') represents the email's header and body of text. Now lets examine the next part (the one that begins after the column): | So in short, the part beginning with '''echo''' and ending just before the column ('''|''') represents the email's header and body of text. Now lets examine the next part (the one that begins after the column): | ||
'''sendmail <span style=color:green>-v -H</span> "<span style=color:blue>exec openssl s_client -quiet -connect smtp.gmail.com:587 - | '''sendmail <span style=color:green>-v -H</span> "<span style=color:blue>exec openssl s_client -quiet -connect smtp.gmail.com:587 -tls1_3 -starttls smtp</span>" <span style=color:red>-f [email protected]</span> <span style=color:purple>-au"[email protected]" -ap"senders.email.password"</span> <span style=color:brown> [email protected]</span>''' | ||
* <span style=color:green>'''-v'''</span> - verbose mode | * <span style=color:green>'''-v'''</span> - verbose mode | ||
* <span style=color:green>'''-H'''</span> - runs connection helper; connection helper allows you to specify additional commands regarding the email (in this case, OpenSSL connection information) | * <span style=color:green>'''-H'''</span> - runs connection helper; connection helper allows you to specify additional commands regarding the email (in this case, OpenSSL connection information) | ||
* <span style=color:blue>'''exec openssl s_client -quiet -connect smtp.gmail.com:587 - | * <span style=color:blue>'''exec openssl s_client -quiet -connect smtp.gmail.com:587 -tls1_3 -starttls smtp'''</span> - OpenSSL connection information; <span style=color:blue>'''smtp.gmail.com:587'''</span> specifies the SMTP server and port. Replace this with email service provider's SMTP settings | ||
* <span style=color:red>'''-f [email protected]'''</span> - sender's email address. This should correspond with the '''from:''' part in the echo command | * <span style=color:red>'''-f [email protected]'''</span> - sender's email address. This should correspond with the '''from:''' part in the echo command | ||
* <span style=color:purple>'''-au"[email protected]" -ap"senders.email.password"'''</span> - what follows after <span style=color:purple>'''-au'''</span> inside the quotation marks is the email service's login user name and by analogy <span style=color:purple>'''-ap'''</span> specifies the email service's login password (<span style=color:purple>'''[email protected]'''</span> and <span style=color:purple>'''senders.email.password'''</span>, in this case) | * <span style=color:purple>'''-au"[email protected]" -ap"senders.email.password"'''</span> - what follows after <span style=color:purple>'''-au'''</span> inside the quotation marks is the email service's login user name and by analogy <span style=color:purple>'''-ap'''</span> specifies the email service's login password (<span style=color:purple>'''[email protected]'''</span> and <span style=color:purple>'''senders.email.password'''</span>, in this case) | ||
| Line 109: | Line 110: | ||
This next method is superior when sending longer messages. Instead of using the echo command, we'll store our email header and body information into a text file. Just as in the example above, let's send an email from the hypothetical address '''[email protected]''' to '''[email protected]''' using Gmail's SMTP settings, but without using echo: | This next method is superior when sending longer messages. Instead of using the echo command, we'll store our email header and body information into a text file. Just as in the example above, let's send an email from the hypothetical address '''[email protected]''' to '''[email protected]''' using Gmail's SMTP settings, but without using echo: | ||
:~# sendmail -v -H "exec openssl s_client -quiet -connect smtp.gmail.com:587 - | :~# sendmail -v -H "exec openssl s_client -quiet -connect smtp.gmail.com:587 -tls1_3 -starttls smtp" <span style=color:red>'''</tmp/mail.txt'''</span> -f [email protected] -au"[email protected]" -ap"pass" [email protected] | ||
As you can see, instead of echo, we're using <span style=color:red>'''</tmp/mail.txt'''</span>, which is the path to the '''mail.txt''' file that stores the email's header and body. This file does not exist in the router, therefore, you should create it yourself. To create a file, use the '''touch''' command: | As you can see, instead of echo, we're using <span style=color:red>'''</tmp/mail.txt'''</span>, which is the path to the '''mail.txt''' file that stores the email's header and body. This file does not exist in the router, therefore, you should create it yourself. To create a file, use the '''touch''' command: | ||
| Line 136: | Line 137: | ||
* '''https://www.putty.org/''' - PuTTY downloads page | * '''https://www.putty.org/''' - PuTTY downloads page | ||
* '''https://wiki.teltonika-networks.com/view/Sending_emails_via_command_line_RutOS''' - Guide for RutOS firmware | |||
[[Category:Email]] | |||