Created
April 22, 2010 19:49
-
-
Save fmoralesc/375721 to your computer and use it in GitHub Desktop.
a vim script for sending emails
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
if (exists("g:loaded_sendmail") && g:loaded_sendmail) || &cp | |
finish | |
endif | |
let g:loaded_sendmail = 1 | |
command! -complete=custom,ListAddresses -nargs=1 Email exec('py sendmail_email("<args>")') | |
fun ListAddresses(A,L,P) | |
return system("(grep -o '84=[[:alnum:]+\.\_\-]*@[[:alnum:]+\.\_\-]*' ~/.thunderbird/*.default/abook.mab && cat /home/felipe/.vim/plugin/sendmail.addresslist) | sed -s 's/84=//' | sort | uniq -u") | |
endfun | |
python <<EOF | |
import vim | |
import smtplib | |
from email.mime.text import MIMEText | |
def sendmail_email(to_address): | |
smtp_server = vim.eval("g:sendmail_smtpserver") | |
smtp_port = vim.eval("g:sendmail_port") | |
from_address = vim.eval("g:sendmail_email") | |
password = vim.eval("g:sendmail_password") | |
body = "\n".join(vim.current.buffer[2:]) | |
msg = MIMEText(body) | |
msg['Subject'] = vim.current.buffer[0] | |
msg['From'] = from_address | |
msg['To'] = to_address | |
server = smtplib.SMTP(smtp_server, smtp_port) | |
server.ehlo() | |
server.starttls() | |
server.ehlo() | |
server.login(from_address, password) | |
server.sendmail(from_address, to_address, msg.as_string()) | |
server.quit() | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment