def test_send_mail(self): """Test send_mail to send email out successfully.""" user_email = '*****@*****.**' messages = self.mail_stub.get_sent_messages( to=config.ADMIN_EMAIL_ADDRESS) self.assertEqual(0, len(messages)) gae_email_services.send_mail(config.SYSTEM_EMAIL_ADDRESS, user_email, config.ADMIN_EMAIL_ADDRESS, 'subject', 'body') messages = self.mail_stub.get_sent_messages( to=config.ADMIN_EMAIL_ADDRESS) self.assertEqual(1, len(messages))
def send_mail(email_subject, email_body, reply_to_email, recipient_email): """Send an email to the given email address. Args: email_subject: str. Subject of the email. email_body: str. Body (message) of the email. reply_to_email: str. The email address that the admin will be replying to. recipient_email: str. The recipient email address. """ gae_email_services.send_mail(config.SYSTEM_EMAIL_ADDRESS, reply_to_email, recipient_email, email_subject, email_body)
def send_mail_to_admin(email_subject, email_body, reply_to_email): """Send an email to the admin email address. The email is sent to the ADMIN_EMAIL_ADDRESS set in config.py. Args: email_subject: str. Subject of the email. email_body: str. Body (message) of the email. reply_to_email: str. The email address that the admin will be replying to. """ gae_email_services.send_mail(config.SYSTEM_EMAIL_ADDRESS, reply_to_email, config.ADMIN_EMAIL_ADDRESS, email_subject, email_body)
def test_unable_to_send_mail(self): """Test send_mail raises exceptions with invalid email addresses.""" user_email = '*****@*****.**' bad_sender_email = 42 with self.assertRaisesRegexp( ValueError, 'Malformed sender email address: %s' % bad_sender_email): gae_email_services.send_mail(bad_sender_email, user_email, config.ADMIN_EMAIL_ADDRESS, 'subject', 'body') bad_reply_email = ' ' with self.assertRaisesRegexp( ValueError, 'Malformed reply-to email address: %s' % bad_reply_email): gae_email_services.send_mail(config.SYSTEM_EMAIL_ADDRESS, bad_reply_email, config.ADMIN_EMAIL_ADDRESS, 'subject', 'body') bad_recipient_email = None with self.assertRaisesRegexp( ValueError, 'Malformed recipient email address: %s' % bad_recipient_email): gae_email_services.send_mail(config.SYSTEM_EMAIL_ADDRESS, user_email, bad_recipient_email, 'subject', 'body')