Created
February 2, 2012 10:29
-
-
Save binux/1722800 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
EMAIL=$1 | |
source vars | |
set -x | |
./pkitool $EMAIL | |
source sendca.sh |
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
#!/bin/bash | |
EMAIL=$1 | |
set -x | |
cp /etc/openvpn/easy-rsa/keys/$EMAIL.crt /tmp/client.crt | |
cp /etc/openvpn/easy-rsa/keys/$EMAIL.key /tmp/client.key | |
echo | ./sendmail.py -a /etc/openvpn/ca.crt /etc/openvpn/ta.key /etc/openvpn/client.config /tmp/client.crt /tmp/client.key -s 'openvpn for ramhost.binux.me' $EMAIL |
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
#!/usr/bin/env python | |
# -*- encoding: utf-8 -*- | |
# vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8: | |
# Author: Binux<huangkuan@duokan.com> | |
# http://binux.me | |
# Created on Wed 11 Jan 2012 04:52:06 PM CST | |
import sys | |
import os.path | |
import argparse | |
import smtplib | |
from email.mime.text import MIMEText | |
from email.mime.base import MIMEBase | |
from email.mime.multipart import MIMEMultipart | |
smtp_host = "smtp.gmail.com" | |
smtp_port = 465 | |
using_ssl = True | |
username = "noreply@binux.me" | |
password = "" | |
parser = argparse.ArgumentParser(description="sendmail.py") | |
parser.add_argument('toaddrs', metavar="ADDR", nargs='+') | |
parser.add_argument('--sender', default="pysendmail@localhost") | |
parser.add_argument('-a', '--attach', nargs='*') | |
parser.add_argument('-s', '--subject', default="pysendmail") | |
args = parser.parse_args() | |
fromaddr = args.sender | |
toaddrs = args.toaddrs | |
subject = args.subject | |
attach = args.attach | |
msg = sys.stdin.read() | |
################################################# | |
if not attach: | |
outer = MIMEText(msg) | |
outer['Subject'] = subject | |
outer['From'] = fromaddr | |
outer['To'] = ", ".join(toaddrs) | |
outer.preamble = 'You will not see this in a MIME-aware mail reader.\n' | |
else: | |
outer = MIMEMultipart() | |
outer['Subject'] = subject | |
outer['From'] = fromaddr | |
outer['To'] = ", ".join(toaddrs) | |
outer.preamble = 'You will not see this in a MIME-aware mail reader.\n' | |
if msg: | |
outer.attach(MIMEText(msg)) | |
for path in attach: | |
dirname, filename = os.path.split(path) | |
with open(path, "rb") as fp: | |
msg = MIMEBase("application", "octet-stream") | |
msg.set_payload(fp.read()) | |
msg.add_header('Content-Disposition', 'attachment', filename=filename) | |
outer.attach(msg) | |
if using_ssl: | |
smtp = smtplib.SMTP_SSL(smtp_host, smtp_port) | |
else: | |
smtp = smtplib.SMTP(smtp_host, smtp_port) | |
if username and password: | |
smtp.login(username, password)[0] | |
smtp.sendmail(fromaddr, toaddrs, outer.as_string()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment