(options, args)
| 72 | process(options, args) |
| 73 | |
| 74 | def process(options, args): |
| 75 | config = get_config(options) |
| 76 | # Write the email |
| 77 | msg = MIMEMultipart() |
| 78 | msg['From'] = config['fromaddr'] |
| 79 | msg['To'] = config['toaddrs'] |
| 80 | msg['Subject'] = options.subject |
| 81 | body = options.body |
| 82 | msg.attach(MIMEText(body, 'plain')) |
| 83 | # Attach image |
| 84 | if options.image_file: |
| 85 | try: |
| 86 | filename = open(options.image_file, "rb") |
| 87 | attach_image = MIMEImage(filename.read()) |
| 88 | attach_image.add_header('Content-Disposition', |
| 89 | 'attachment; filename = %s'%options.image_file) |
| 90 | msg.attach(attach_image) |
| 91 | filename.close() |
| 92 | except: |
| 93 | msg.attach(MIMEText('Image attachment error', 'plain')) |
| 94 | # Converting email to text |
| 95 | text = msg.as_string() |
| 96 | |
| 97 | # The actual mail send |
| 98 | server = smtplib.SMTP('smtp.gmail.com:587') |
| 99 | server.ehlo() |
| 100 | server.starttls() |
| 101 | server.ehlo() |
| 102 | server.login(config['username'],config['password']) |
| 103 | server.sendmail(config['fromaddr'], config['toaddrs'], text) |
| 104 | server.quit() |
| 105 | |
| 106 | def get_config(options): |
| 107 | conf = {} |
no test coverage detected