- Sending mail on python code running on Raspberry Pi.
- Sending mail on MATLAB code running on my labtop.
Second method should need receiving data from RPi. I'll use similar code with the one which I used in plotting sensor data.
There could be several codes for sending mail, and here're some example codes I used.
1) Sending mail on Python (Raspberry Pi)
import smtplib
def send(addr, s):
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(‘foo@gmail.com', ‘pwd')
server.sendmail(‘foo@gmail.com', addr, s)
server.quit()
I put my Gmail account and password in server.login(). With this, we can easily send a mail.
**Also here's important point. We should change account setting for Rasperry Pi here (https://www.google.com/settings/security/lesssecureapps) when authentication probelm occurs unless we put correct account info and codes**
2) Sending mail on MATLAB
mail = 'foo@gmail.com';
password = 'pwd';
server = 'smtp.gmail.com';
setpref('Internet','E_mail',mail);
setpref('Internet','SMTP_Server',server);
setpref('Internet','SMTP_Username',mail);
setpref('Internet','SMTP_Password',password);
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth','true');
props.setProperty('mail.smtp.socketFactory.class','javax.net.ssl.SSLSocketFactory');
props.setProperty('mail.smtp.socketFactory.port','465');
sendmail('addr','Alert!','Msg From MATLAB');
Both method can occur short delay for sending mail when the function works. You can also send text message using '10digits'@vtext.com (for verizon, there're similar things for others).
댓글 없음:
댓글 쓰기