Last active
August 29, 2015 14:05
-
-
Save chriddyp/aae589fbf47a16237ab4 to your computer and use it in GitHub Desktop.
Send Plotly (https://plot.ly) graphs to Evernote Notes in MATLAB with Evernote's Email API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function plotly2evernote(plotly_urls, note_name, notebook_name, note_title, evernote_email) | |
% Send Plotly Graphs to Evernote via Evernote's Email API | |
% Example note: https://www.evernote.com/shard/s453/sh/4536647a-335f-46e7-95f8-e1aec1894959/0e21dba818157388a483e066d0382bcf | |
% `plotly_urls`: cell array of plotly unique urls, e.g. | |
% {'https://plot.ly/~chris/2549', 'https://plot.ly/~chris/2550', 'https://plot.ly/~chris/2551'} | |
% `evernote_email`: Evernote Email, found in your Evernote Account Info | |
% | |
% To run, setup email in matlab, e.g. run: | |
% | |
% >> setpref('Internet','E_mail', your_email_address); | |
% >> setpref('Internet','SMTP_Server', your_smpt_server); % e.g. 'smtp.gmail.com' | |
% >> setpref('Internet','SMTP_Username',your_email_address_or_username); | |
% >> setpref('Internet','SMTP_Password',your_email_password); | |
% % Gmail server. | |
% 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'); | |
html_string = create_evernote_plotly_html_attachment(note_title, plotly_urls); | |
temp_filename = 'temp_evernote_attachment.html'; | |
fid = fopen(temp_filename, 'w'); | |
fprintf(fid, html_string); | |
fclose(fid); | |
sendmail(evernote_email, [note_name ' @', notebook_name], '', temp_filename); | |
end | |
function html = create_evernote_plotly_html_attachment(note_title, plotly_urls) | |
html = ... | |
['<html>'... | |
'<body width="1200px">'... | |
'<h1>' note_title '</h1>']; | |
for i=1:length(plotly_urls) | |
html = [html ... | |
'<a href="' plotly_urls{i} '">'... | |
'<img src="' plotly_urls{i} '.png">'... | |
'</a>' | |
]; | |
end | |
html = [html... | |
'</body>'... | |
'</html>'... | |
]; | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment