def get_message(self, **kwargs): """ Get message object for email """ config = get_configurations() message = Mail() if "from_email" in kwargs: sender = Email() message_content = kwargs.get("message_content", "") sender.name = kwargs.get("sender", config['SENDGRID']['sender']) sender.email = kwargs.get("from_email", config['SENDGRID']['fromemail']) message.from_email = sender if "subject" in kwargs: message.subject = kwargs.get("subject", "") if "text" in kwargs: content = Content("text/plain", kwargs.get("text", "")) message.add_content(content) if "html" in kwargs: content = Content("text/html", kwargs.get("html", "")) message.add_content(content) if "category" in kwargs: category = Category(kwargs.get("category", "")) message.add_category(category) personalization = self.create_personalization(**kwargs) if personalization: message.add_personalization(personalization) return message.get()
def get_message(self, **kwargs): """ Get message object for email """ message = Mail() if "from_email" in kwargs: sender = Email() message_content = kwargs.get("message_content", "") sender.name = message_content.get("sender", emailconf.DEFAULT_SENDER) sender.email = kwargs.get("from_email", emailconf.DEFAULT_SENDER_EMAIL) message.from_email = sender if "subject" in kwargs: message.subject = kwargs.get("subject", "") if "text" in kwargs: content = Content("text/plain", kwargs.get("text", "")) message.add_content(content) if "html" in kwargs: content = Content("text/html", kwargs.get("html", "")) message.add_content(content) if "category" in kwargs: category = Category(kwargs.get("category", "")) message.add_category(category) personalization = self.create_personalization(**kwargs) if personalization: message.add_personalization(personalization) return message.get()
def _process_email_addr(self, email_addr): from_name, from_email = rfc822.parseaddr(email_addr) # Python sendgrid client should improve # sendgrid/helpers/mail/mail.py:164 if not from_name: from_name = None email = Email() email.email = from_email email.name = from_name return email
def sendmail(subject, content, to): api_key = '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' sg = SendGridAPIClient(apikey=api_key) mail = Mail() email = Email() email.email = '*****@*****.**' email.name = 'Openwob' mail.from_email = email mail.subject = u'Openwob: ' + subject personalization = Personalization() for address in to: personalization.add_to(Email(address)) mail.add_personalization(personalization) mail.add_content(Content("text/plain", content)) sg.client.mail.send.post(request_body=mail.get())
def test_empty_obj_add_email(self): email = Email() address = "*****@*****.**" email.email = address self.assertEqual(email.email, address)