Jump to content

Sending emails via command line: Difference between revisions

Line 61: Line 61:
==Sending emails==
==Sending emails==


RUT routers use the '''sendmail''' program to send emails. sendmail is a very simple MTA (Mail Transfer Agent), which implements the SMTP (Simple Mail Transfer Protocol) amongst others and can be used to transmit emails, typically on Linux dedicated or virtual servers.
RUT routers use the '''sendmail''' program to send emails. sendmail is a very simple MTA (Mail Transfer Agent), which implements the '''SMTP''' ('''Simple Mail Transfer Protocol''') amongst others and can be used to transmit emails, typically on Linux dedicated or virtual servers.


There is no need to install anything else, because RUT routers have sendmail implemented in their Firmware. So, if you followed the steps above, you should be ready to send emails via command line.  
There is no need to install anything else, because RUT routers have sendmail implemented in their Firmware. So, if you followed all the steps above, you should be ready to send emails via command line.  


===Method 1===
===Method 1===
Line 88: Line 88:
  JustTesting</span>  
  JustTesting</span>  


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 The next part (beginning 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 -tls1 -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>'''
'''sendmail <span style=color:green>-v -H</span> "<span style=color:blue>exec openssl s_client -quiet -connect smtp.gmail.com:587 -tls1 -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>'''
Line 94: Line 94:
* <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 -tls1 -starttls smtp'''</span> - OpenSSL connection information; <span style=color:blue>'''smtp.gmail.com:587'''</span> specifies the SMTP server and port. Replace with email service provider's relevant SMTP settings
* <span style=color:blue>'''exec openssl s_client -quiet -connect smtp.gmail.com:587 -tls1 -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 username 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 log in password (<span style=color:purple>'''[email protected]'''</span> and <span style=color:purple>'''senders.email.password'''</span>, in this case)
* <span style=color:brown>'''[email protected]'''</span> - specifies the recipient's email address
* <span style=color:brown>'''[email protected]'''</span> - specifies the recipient's email address


Line 109: Line 109:
  :~# sendmail -v -H "exec openssl s_client -quiet -connect smtp.gmail.com:587 -tls1 -starttls smtp" <span style=color:red>'''</tmp/mail.txt'''</span> -f [email protected] -au"[email protected]" -ap"pass"[email protected]
  :~# sendmail -v -H "exec openssl s_client -quiet -connect smtp.gmail.com:587 -tls1 -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 using 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:


  :~# touch /tmp/mail.txt
  :~# touch /tmp/mail.txt
Line 119: Line 119:
  :~# vi /tmp/mail.txt
  :~# vi /tmp/mail.txt


When using ''vi'' pres the '''i''' key on your keyboard to start editing. To finish editing and save changes press the "Escape" button, type ''':x''' and press "Enter":
When using ''vi'' pres the '''i''' button on your keyboard to start editing. To finish editing and save changes press the "Escape" button, type ''':x''' and press "Enter":


[[File:Vi text file.png]]
[[File:Vi text file.png]]
Line 127: Line 127:
The most important thing to remember when following this guide, is to replace the information in the given commands with data that is relevant to you.  
The most important thing to remember when following this guide, is to replace the information in the given commands with data that is relevant to you.  


Also, a lot of email service providers will block sign-in attempts from programs like this. To get around this, enable '''Access for less secure apps''' on your email account. Doing this will be different for different services. We suggest that you use an Internet search engine for information on how to enable Access for less secure apps on your email. In any case, it should be as simple as flipping an ON/OFF switch.
Furthermore, a lot of email service providers will block sign-in attempts from programs like sendmail. To get around this, enable '''Access for less secure apps''' on your email account. Doing this will be different for different services. We suggest that you use an Internet search engine for information on how to enable Access for less secure apps on your email. In any case, it should be as simple as flipping an ON/OFF switch.


'''WARNING''': enabling Access for less secure apps may leave your email vulnerable to attacks from other parties! Use it at your own risk.
'''WARNING''': enabling Access for less secure apps may leave your email vulnerable to attacks from other parties! Use it at your own risk.