if os.path.isfile( "/opt/openvpn/ca/keys/" + username + ".crt"): #print "Cert for " + username + " exists" # Read in the text portion of the mail with open('/opt/openvpn/etc/sendcertagain-mailbody.txt', 'r') as myfile: text=myfile.read() # Set filenames for the attachment configfilename="charite-" + username + ".ovpn" # Define key material paths keyfilename="/opt/openvpn/ca/keys/" + username + ".key"; crtfilename="/opt/openvpn/ca/keys/" + username + ".crt"; cafilename="/opt/openvpn/ca/keys/ca.crt"; # Open key material with open('/opt/openvpn/etc/charite.ovpn.template', 'r') as myfile: configtemplatefile = myfile.read() with open(cafilename, 'r') as myfile: cafile = myfile.read() with open(keyfilename, 'r') as myfile: keyfile = myfile.read() with open(crtfilename, 'r') as myfile: crtfile = myfile.read() sender = str(Header("Charité VPN administrator", "utf8")) + " " subject = Header("Configuration file to your Charité VPN access","utf8") configfile = configtemplatefile + "\n" + cafile + "\n\n" + keyfile + "\n\n" + crtfile + "\n" send_mail_ssl(sender, email, subject, text, files=[], attachments={configfilename: configfile} ) print "Configuration file was sent to " + email + "." else: print "User " + username + " has no certificate" sys.exit(1) if os.path.isfile( "/opt/openvpn/ca/keys/" + username + ".crt"): #print "Cert for " + username + " exists" # Read in the text part of the mail with open('/opt/openvpn/etc/sendcertagain-mailbody.txt', 'r') as myfile: text=myfile.read() # Set attachment filenames configfilename="charite-" + username + ".ovpn" # Define key material paths keyfilename="/opt/openvpn/ca/keys/" + username + ".key"; crtfilename="/opt/openvpn/ca/keys/" + username + ".crt"; cafilename="/opt/openvpn/ca/keys/ca.crt"; # Open key material with open('/opt/openvpn/etc/charite.ovpn.template', 'r') as myfile: configtemplatefile = myfile.read() with open(cafilename, 'r') as myfile: cafile = myfile.read() with open(keyfilename, 'r') as myfile: keyfile = myfile.read() with open(crtfilename, 'r') as myfile: crtfile = myfile.read() sender = str(Header("Charité VPN Administrator", "utf8")) + " " subject = Header("Configuration file to your Charité VPN access","utf8") configfile = configtemplatefile + "\n" + cafile + "\n\n" + keyfile + "\n\n" + crtfile + "\n" send_mail_ssl(sender, email, subject, text, files=[], attachments={configfilename: configfile} ) print "Configuration file was sent to " + email + "." else: print "User " + username + " has no Certificate" sys.exit(1)