def send(self, to_index=None): """ send gmail """ if self.now is not None: gmail = Gmail(self.gsetting) gmail.send(to_index, self.fname, self.now + '.mp4')
class Server: def __init__(self, credentials, address='0.0.0.0', port=0, forward=False): self.forward = forward self.gmail = Gmail() self.ftp_server = FTPServer(credentials, (address, port), FTPSession) self.address, self.port = self.ftp_server.socket.getsockname() @property def images(self): return self.ftp_server.images def forward_received_images_on_smtp(self): while self.forward: sleep(60) batch = [] while not self.images.empty(): batch.append(self.images.get()) if batch: message = Message(Configuration.email_subject, batch) self.gmail.connect() self.gmail.send(message) self.gmail.disconnect() def listen(self): Thread(target=self.ftp_server.serve_forever).start() Thread(target=self.forward_received_images_on_smtp).start() def quit(self): self.forward = False self.ftp_server.shutdown()
def main(json_data, context): currentNumbers, outputMessage = getNumbers(outputMessage = '') outputMessage = checkNumbers(currentNumbers, outputMessage) g = Gmail() g.setFrom('*****@*****.**') g.addRecipient('*****@*****.**') g.subject("Do you want to be a milli?") g.message(outputMessage) username = os.environ['username'] appkey = os.environ["appkey"] g.setAuth(username, appkey) g.send()
def main(): # Bob is sender, Alide is destination. from_address = "*****@*****.**" to_address = "*****@*****.**" file_info = {"type": "pdf", "subtype": "pdf"} a_title = u"Research: slide of today" a_body = u'''Dear Alice. Good afternoon, I'm Bob. I attach today's slide(2015-04-01.pdf) to this mail. ----------- Bob Marley. Kyoto Sangyo University in Japan. [email protected]. ''' files = [] for a_file in os.listdir('.'): if ".pdf" in a_file: files.append(a_file) if len(files) >= 2: print "PDF is only one." for a_file in files: print a_file.decode('utf-8') elif len(files) == 0: print "PDF is not found." elif len(files) == 1: a_file = files[0] file_info["name"] = a_file file_info["path"] = "./" + a_file comment = raw_input("comment > ").decode('utf-8') if len(comment) == 0: a_body = a_body % (a_file.decode('utf-8'), comment) else: a_body = a_body % (a_file.decode('utf-8'), "\n" + comment) print "\n" print a_title print "*" * 50 print a_body print "*" * 50 if raw_input("Is This OK? ") == 'y': a_gmail = Gmail() a_message = a_gmail.create_message(from_address, to_address, a_title, file_info, a_body) a_gmail.send(from_address, to_address, a_message) print u"Sent!" else: print u"Sending miss."
def send_confirmation(user_email=None): print 'sending email confirmation' if user_email is None: print 'Email not provided for send_confirmation()' Response("Email address not provided", 200) token = generate_confirmation_token(user_email) url = "http://0.0.0.0:5000/confirm?confirm_token=%s&user_email=%s" % ( token, user_email) gmail = Gmail(gmail_user="******", gmail_password="******") gmail.mail_from_name = "Crypto Bot" gmail.mail_from = "***********@gmail.com" gmail.mail_subject = "Please confirm your account" gmail.mail_to = user_email gmail.mail_body = "<strong>Thank you for signing up with **************</strong><br>Click the URL below to activate your account <a href='%s'>%s</a>" % ( url, url) gmail.send()
def send_email(blog_id, post_id): post = (blogger_service().posts().get( blogId=blog_id, postId=post_id ).execute()) form = forms.Form() recipients = Recipient.query.filter_by(blog_id=blog_id).all() addresses = [r.email for r in recipients] if form.validate_on_submit(): html = flask.render_template( 'email.html', title=post['title'], content=flask.Markup(post['content'])) text = 'A new blog post is available at ' + post['url'] gmail = Gmail(gmail_service()) gmail.send(addresses, post['title'], text, html) flask.flash(u"Email sent - {title}".format(**post), "success") return flask.redirect(flask.url_for('.blog', blog_id=blog_id)) return flask.render_template('send_email.html', post=post, form=form, addresses=addresses)
class Notifier(object): def __init__(self): self.gmail = Gmail(config.GMAIL_INFO['email'], config.GMAIL_INFO['pw']) self.subject = 'New alert from buildapc watcher' self.to_emails = config.EMAIL_TO self.to_sms = config.SMS_TO def alert(self, post): print(post['title']) self._alert_emails(post) self._alert_smses(post) def _alert_emails(self, post): body = self._build_email_msg_body(post) for to_email in self.to_emails: self.gmail.send(to_email, self.subject, body) def _build_email_msg_body(self, post): date = datetime.fromtimestamp(post['created']) date = date.replace(tzinfo=timezone.utc).astimezone(tz=None) return '\r\n\r\n'.join([ post['title'], post['link'], post['reddit_url'], str(date), post['body'] ]) def _alert_smses(self, post): body = self._build_sms_msg_body(post) for sms in self.to_sms: self.gmail.send(get_sms_address(sms, self.to_sms[sms]), self.subject, body) def _build_sms_msg_body(self, post): date = datetime.fromtimestamp(post['created']) date = date.replace(tzinfo=timezone.utc).astimezone(tz=None) return '\r\n\r\n'.join( [post['title'], post['link'], post['reddit_url'], str(date)])
class CommandHandler(object): def __init__(self): self.gpg = None self.gmail = None self.gpgmail = None self.initialized = False self.logger = logging.getLogger('CommandHandler') def parse(self, bundle): if not 'command' in bundle: self.logger.error("no command in bundle {}".format(bundle)) return None result = None command = bundle["command"] if command == 'init': result = self.init(bundle) else: # do nothing if not intialized if not self.initialized: return False if command == 'verify': result = self.verify(bundle) elif command == 'sign': result = self.sign(bundle) elif command == 'import': result = self.import_key(bundle) return result def init(self, bundle): if not 'username' in bundle: return False self.gpg = GPG(use_agent=True) self.gpgmail = GPGMail(self.gpg) self.gmail = Gmail(bundle['username']) self.initialized = True return {'version': VERSION} def verify(self, bundle): if not 'id' in bundle: return False id = bundle['id'] def _verify(): mail = self.gmail.get(id) return self.gpgmail.verify(mail) # verify the message only if bundle['force'] = true if 'force' in bundle and bundle['force']: return _verify() # or content_type of message is 'multipart/signed' headers = self.gmail.get_headers(id, ['Content-Type', 'Message-ID']) if 'Content-Type' in headers: content_type = headers['Content-Type'] if content_type.find('multipart/signed') >= 0: return _verify() # or if message is multipart and it may contain a pgp-signature is_multipart = content_type.find('multipart/') >= 0 if (is_multipart and 'Message-ID' in headers): rfc822msgid = headers['Message-ID'] query = '("BEGIN PGP SIGNATURE" "END PGP SIGNATURE")' match = self.gmail.message_matches(id, query, rfc822msgid) if match: return _verify() # else return None def sign(self, bundle): if not 'id' in bundle: return False result = False id = bundle['id'] try: draft = self.gmail.get(id) new_message = self.gpgmail.sign(draft) if new_message: self.gmail.send(id, new_message) result = True except Exception, e: self.logger.exception(e) finally:
def test_can_send_mail_with_a_multiple_image(self): gmail = Gmail() gmail.connect() message = Message('Test', [open('test/snapshot.jpg', 'rb').read()]*50) gmail.send(message) gmail.disconnect()
class CommandHandler(object): def __init__(self): self.gpg = None self.gmail = None self.gpgmail = None self.initialized = False self.logger = logging.getLogger('CommandHandler') def parse(self, bundle): if not 'command' in bundle: self.logger.error("no command in bundle {}".format(bundle)) return None result = None command = bundle["command"] if command == 'init': result = self.init(bundle) else: # do nothing if not intialized if not self.initialized: return False if command == 'verify': result = self.verify(bundle) elif command == 'sign': result = self.sign(bundle) elif command == 'import': result = self.import_key(bundle) return result def init(self, bundle): if not 'username' in bundle: return False self.gpg = GPG(use_agent=True) self.gpgmail = GPGMail(self.gpg) self.gmail = Gmail(bundle['username']) self.initialized = True return {'version': VERSION} def verify(self, bundle): if not 'id' in bundle: return False id = bundle['id'] def _verify(): mail = self.gmail.get(id) return self.gpgmail.verify(mail) # verify the message only if bundle['force'] = true if 'force' in bundle and bundle['force']: return _verify() # or content_type of message is 'multipart/signed' headers = self.gmail.get_headers(id, ['Content-Type', 'Message-ID']) if 'Content-Type' in headers: content_type = headers['Content-Type'] if content_type.find('multipart/signed') >= 0: return _verify() # or if message is multipart and it may contain a pgp-signature is_multipart = content_type.find('multipart/') >= 0 if (is_multipart and 'Message-ID' in headers): rfc822msgid = headers['Message-ID'] query = 'filename:asc || filename:gpg || filename:signature || ("BEGIN PGP SIGNATURE" "END PGP SIGNATURE")' match = self.gmail.message_matches(id, query, rfc822msgid) if match: return _verify() # else return None def sign(self, bundle): if not 'id' in bundle: return False result = False id = bundle['id'] try: draft = self.gmail.get(id) new_message = self.gpgmail.sign(draft) if new_message: self.gmail.send(id, new_message) result = True except Exception as e: self.logger.exception(e) finally: return result def import_key(self, bundle): if not 'id' in bundle: return False imp = self.gpg.recv_keys('keyserver.ubuntu.com', bundle['id']) result = imp.imported > 0 complete_result = imp.results[0] self.logger.info("import key {} - {}: {}".format( complete_result['fingerprint'], result, complete_result['text'])) return result
def send(email): mail = Mail(email['user'], email['password']) mail.subject = 'Feeds from ' + time.strftime('%Y-%m-%d') + '.html' mail.add_recipient(email['kindle']) mail.attach_file(OUTPUT, rename=mail.subject) mail.send()