                                          ___              
                             ,----.     ,--.'|_            
                            /   /  \-.  |  | :,'   __  ,-. 
                 ,--,  ,--,|   :    :|  :  : ' : ,' ,'/ /| 
                 |'. \/ .`||   | .\  ..;__,'  /  '  | |' | 
                 '  \/  / ;.   ; |:  ||  |   |   |  |   ,' 
                  \  \.' / '   .  \  |:__,'| :   '  :  /   
                   \  ;  ;  \   `.   |  '  : |__ |  | '    
                  / \  \  \  `--'""| |  |  | '.'|;  : |    
                ./__;   ;  \   |   | |  ;  :    ;|  , ;    
                |   :/\  \ ;   |   | :  |  ,   /  ---'     
                `---'  `--`    `---'.|   ---`-'            
                                 `---`                                  12/2016

     ___              _   __  __      _ _   _        __  __         _   _    
    / __| ___ _ _  __| | |  \/  |__ _(_) | (_)_ _   |  \/  |_  _ __| |_(_)__ 
    \__ \/ -_) ' \/ _` | | |\/| / _` | | | | | ' \  | |\/| | || (_-<  _| / _|
    |___/\___|_||_\__,_| |_|  |_\__,_|_|_| |_|_||_| |_|  |_|\_, /__/\__|_\__|
                                                            |__/             

                      Tested with Mystic BBS 1.12+
                      

~'`^`''~*-,._.,-*~'`^`'~*-,._.,-(  Description )~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*

  This text describes how to setup Mystic BBS to send emails from or within your
system. The use of this feature depends on you. You can send an email when a 
user logins to the BBS, or enters a specific area or send a small message to the
sysop.


~'`^`'~*-,._.,-*~'`^`'~*-,._.,-( Requirements )~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*

  You must have Python 3 installed and a Google account to use. Your Google
account will be the sender of the emails, so it must be legit and yours. You can
modify the script to use other SMTP servers, but for now, i will describe for
Google only.

  The process is described for Linux/Raspberry, but can also adopted to Windows.


~'`^`'~*-,._.,-*~'`^`'~*-,._.,-(   Process   )~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*

  You need two scripts. The first is a Python 3 script and the other a simple
BASH script. Copy both of them and paste them into different files. Make sure
to make them executables, with the chmod command.

1. Make The Scripts...

----[ mail.py ]------------------------------------------- COPY HERE ----------
#!/usr/bin/python3
import smtplib
from sys import argv

script, tom, subject, text = argv

# Gmail Sign In
gmail_sender = 'youremail@gmail.com'
gmail_passwd = 'your_password'

server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(gmail_sender, gmail_passwd)

BODY = '\r\n'.join(['To: %s' % tom,
                    'From: %s' % gmail_sender,
                    'Subject: %s' % subject,
                    '', text])

try:
    server.sendmail(gmail_sender, [tom], BODY)
    #print ('email sent')
except:
    print ('mail.py - Error Sending Mail')

server.quit()
----[ mail.py ]--------------------------------------------------------- END --


----[ email.sh ]------------------------------------------- COPY HERE ---------
#!/bin/bash
/home/pi/mystic/mail.py Receive_Address Subject "$1" &
----[ email.sh ]--------------------------------------------------------- END -
  
2. Make the scripts, executable.

  To make them executable write this:
  
  chmod +x mail.py
  chmod +x email.sh

3. Move the files to Mystic Folder
  
  Put both scripts into your Mystic Folder ex: /home/pi/mystic/
  
  You are almost done. The only thing missing is to create commands from within
the Mystic BBS to send an email.

~'`^`'~*-,._.,-*~'`^`'~*-,._.,-(    Config    )~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*

  1. Open Mystic Configuration (mystic -cfg) and edit a menu of your choice. For 
example we will edit the main menu.

  2. Choose the Messages Command/Area and edit it
  
  3. Press Tab to go to the Command area
  
  4. Press / and Insert a new command with I
  
  5. At the box, enter these:
  
               Command │ (DD) Exec external program                           
                  Data │ /home/pi/mystic/email.sh "Your Message"   
                Access │                                           
               Execute │ Select   
               
  Press ESC as many times to exit the editor and save the menu. Now go to your
BBS and check if its working. :)

~'`^`'~*-,._.,-*~'`^`'~*-,._.,-(     Risks    )~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*

  You are sending mails... you shouldn't let users to send whatever they want
or send too much emails, cause then Google may think it as a spam. Use this 
feature properly and with caution.

/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
 

