def send_user_query_email(sender_id, recipient_ids, email_subject, email_body, email_intent): """Sends an email to all the recipients of the query. Args: sender_id: str. The ID of the user sending the email. recipient_ids: list(str). The user IDs of the email recipients. email_subject: str. The subject of the email. email_body: str. The body of the email. email_intent: str. The intent string, i.e. the purpose of the email. Returns: bulk_email_model_id: str. The ID of the bulk email model. """ bulk_email_model_id = email_models.BulkEmailModel.get_new_id('') sender_name = user_services.get_username(sender_id) sender_email = user_services.get_email_from_user_id(sender_id) _send_bulk_mail(recipient_ids, sender_id, email_intent, email_subject, email_body, sender_email, sender_name, instance_id=bulk_email_model_id) return bulk_email_model_id
def send_user_query_email(sender_id, recipient_ids, email_subject, email_body, email_intent): bulk_email_model_id = email_models.BulkEmailModel.get_new_id('') sender_name = user_services.get_username(sender_id) sender_email = user_services.get_email_from_user_id(sender_id) _send_bulk_mail(recipient_ids, sender_id, email_intent, email_subject, email_body, sender_email, sender_name, bulk_email_model_id) return bulk_email_model_id
def send_user_query_email( sender_id, recipient_ids, email_subject, email_body, email_intent): bulk_email_model_id = email_models.BulkEmailModel.get_new_id('') sender_name = user_services.get_username(sender_id) sender_email = user_services.get_email_from_user_id(sender_id) _send_bulk_mail( recipient_ids, sender_id, email_intent, email_subject, email_body, sender_email, sender_name, bulk_email_model_id) return bulk_email_model_id
def send_test_email_for_bulk_emails(tester_id, email_subject, email_body): tester_name = user_services.get_username(tester_id) tester_email = user_services.get_email_from_user_id(tester_id) return _send_email(tester_id, tester_id, feconf.BULK_EMAIL_INTENT_TEST, email_subject, email_body, tester_email, sender_name=tester_name)
def _send_email(recipient_id, sender_id, intent, email_subject, email_html_body, sender_email, bcc_admin=False, sender_name=None): """Sends an email to the given recipient. This function should be used for sending all user-facing emails. Raises an Exception if the sender_id is not appropriate for the given intent. Currently we support only system-generated emails and emails initiated by moderator actions. """ if sender_name is None: sender_name = EMAIL_SENDER_NAME.value _require_sender_id_is_valid(intent, sender_id) recipient_email = user_services.get_email_from_user_id(recipient_id) cleaned_html_body = html_cleaner.clean(email_html_body) if cleaned_html_body != email_html_body: log_new_error( 'Original email HTML body does not match cleaned HTML body:\n' 'Original:\n%s\n\nCleaned:\n%s\n' % (email_html_body, cleaned_html_body)) return raw_plaintext_body = cleaned_html_body.replace('<br/>', '\n').replace( '<br>', '\n').replace('<li>', '<li>- ').replace('</p><p>', '</p>\n<p>') cleaned_plaintext_body = html_cleaner.strip_html_tags(raw_plaintext_body) if email_models.SentEmailModel.check_duplicate_message( recipient_id, email_subject, cleaned_plaintext_body): log_new_error('Duplicate email:\n' 'Details:\n%s %s\n%s\n\n' % (recipient_id, email_subject, cleaned_plaintext_body)) return def _send_email_in_transaction(): sender_name_email = '%s <%s>' % (sender_name, sender_email) email_services.send_mail(sender_name_email, recipient_email, email_subject, cleaned_plaintext_body, cleaned_html_body, bcc_admin) email_models.SentEmailModel.create(recipient_id, recipient_email, sender_id, sender_name_email, intent, email_subject, cleaned_html_body, datetime.datetime.utcnow()) return transaction_services.run_in_transaction(_send_email_in_transaction)
def send_test_email_for_bulk_emails(tester_id, email_subject, email_body): tester_name = user_services.get_username(tester_id) tester_email = user_services.get_email_from_user_id(tester_id) return _send_email( tester_id, tester_id, feconf.BULK_EMAIL_INTENT_TEST, email_subject, email_body, tester_email, sender_name=tester_name, )
def send_test_email_for_bulk_emails(tester_id, email_subject, email_body): """Sends a test email to the tester. Args: tester_id: str. The user ID of the tester. email_subject: str. The subject of the email. email_body: str. The body of the email. """ tester_name = user_services.get_username(tester_id) tester_email = user_services.get_email_from_user_id(tester_id) _send_email( tester_id, tester_id, feconf.BULK_EMAIL_INTENT_TEST, email_subject, email_body, tester_email, sender_name=tester_name)
def _send_email( recipient_id, sender_id, intent, email_subject, email_html_body, sender_email, bcc_admin=False, sender_name=None): """Sends an email to the given recipient. This function should be used for sending all user-facing emails. Raises an Exception if the sender_id is not appropriate for the given intent. Currently we support only system-generated emails and emails initiated by moderator actions. """ if sender_name is None: sender_name = EMAIL_SENDER_NAME.value _require_sender_id_is_valid(intent, sender_id) recipient_email = user_services.get_email_from_user_id(recipient_id) cleaned_html_body = html_cleaner.clean(email_html_body) if cleaned_html_body != email_html_body: log_new_error( 'Original email HTML body does not match cleaned HTML body:\n' 'Original:\n%s\n\nCleaned:\n%s\n' % (email_html_body, cleaned_html_body)) return raw_plaintext_body = cleaned_html_body.replace('<br/>', '\n').replace( '<br>', '\n').replace('<li>', '<li>- ').replace('</p><p>', '</p>\n<p>') cleaned_plaintext_body = html_cleaner.strip_html_tags(raw_plaintext_body) if email_models.SentEmailModel.check_duplicate_message( recipient_id, email_subject, cleaned_plaintext_body): log_new_error( 'Duplicate email:\n' 'Details:\n%s %s\n%s\n\n' % (recipient_id, email_subject, cleaned_plaintext_body)) return def _send_email_in_transaction(): sender_name_email = '%s <%s>' % (sender_name, sender_email) email_services.send_mail( sender_name_email, recipient_email, email_subject, cleaned_plaintext_body, cleaned_html_body, bcc_admin) email_models.SentEmailModel.create( recipient_id, recipient_email, sender_id, sender_name_email, intent, email_subject, cleaned_html_body, datetime.datetime.utcnow()) return transaction_services.run_in_transaction(_send_email_in_transaction)
def _send_email(recipient_id, sender_id, intent, email_subject, email_html_body): """Sends an email to the given recipient. This function should be used for sending all user-facing emails. Raises an Exception if the sender_id is not appropriate for the given intent. Currently we support only system-generated emails and emails initiated by moderator actions. """ _require_sender_id_is_valid(intent, sender_id) recipient_email = user_services.get_email_from_user_id(recipient_id) cleaned_html_body = html_cleaner.clean(email_html_body) if cleaned_html_body != email_html_body: log_new_error( "Original email HTML body does not match cleaned HTML body:\n" "Original:\n%s\n\nCleaned:\n%s\n" % (email_html_body, cleaned_html_body) ) return raw_plaintext_body = cleaned_html_body.replace("<br/>", "\n").replace("<br>", "\n").replace("</p><p>", "</p>\n<p>") cleaned_plaintext_body = html_cleaner.strip_html_tags(raw_plaintext_body) def _send_email_in_transaction(): sender_email = "%s <%s>" % (EMAIL_SENDER_NAME.value, feconf.SYSTEM_EMAIL_ADDRESS) email_services.send_mail( sender_email, recipient_email, email_subject, cleaned_plaintext_body, cleaned_html_body ) email_models.SentEmailModel.create( recipient_id, recipient_email, sender_id, sender_email, intent, email_subject, cleaned_html_body, datetime.datetime.utcnow(), ) return transaction_services.run_in_transaction(_send_email_in_transaction)
def _send_email(recipient_id, sender_id, intent, email_subject, email_html_body, sender_email, bcc_admin=False, sender_name=None, reply_to_id=None): """Sends an email to the given recipient. This function should be used for sending all user-facing emails. Raises an Exception if the sender_id is not appropriate for the given intent. Currently we support only system-generated emails and emails initiated by moderator actions. Args: recipient_id: str. The user ID of the recipient. sender_id: str. The user ID of the sender. intent: str. The intent string for the email, i.e. the purpose/type. email_subject: str. The subject of the email. email_html_body: str. The body (message) of the email. sender_email: str. The sender's email address. bcc_admin: bool. Whether to send a copy of the email to the admin's email address. sender_name: str or None. The name to be shown in the "sender" field of the email. reply_to_id: str or None. The unique reply-to id used in reply-to email address sent to recipient. """ if sender_name is None: sender_name = EMAIL_SENDER_NAME.value _require_sender_id_is_valid(intent, sender_id) recipient_email = user_services.get_email_from_user_id(recipient_id) cleaned_html_body = html_cleaner.clean(email_html_body) if cleaned_html_body != email_html_body: log_new_error( 'Original email HTML body does not match cleaned HTML body:\n' 'Original:\n%s\n\nCleaned:\n%s\n' % (email_html_body, cleaned_html_body)) return raw_plaintext_body = cleaned_html_body.replace('<br/>', '\n').replace( '<br>', '\n').replace('<li>', '<li>- ').replace('</p><p>', '</p>\n<p>') cleaned_plaintext_body = html_cleaner.strip_html_tags(raw_plaintext_body) if email_models.SentEmailModel.check_duplicate_message( recipient_id, email_subject, cleaned_plaintext_body): log_new_error('Duplicate email:\n' 'Details:\n%s %s\n%s\n\n' % (recipient_id, email_subject, cleaned_plaintext_body)) return def _send_email_in_transaction(): """Sends the email to a single recipient.""" sender_name_email = '%s <%s>' % (sender_name, sender_email) email_services.send_mail(sender_name_email, recipient_email, email_subject, cleaned_plaintext_body, cleaned_html_body, bcc_admin, reply_to_id=reply_to_id) email_models.SentEmailModel.create(recipient_id, recipient_email, sender_id, sender_name_email, intent, email_subject, cleaned_html_body, datetime.datetime.utcnow()) transaction_services.run_in_transaction(_send_email_in_transaction)
def _send_email( recipient_id, sender_id, intent, email_subject, email_html_body, sender_email, bcc_admin=False, sender_name=None, reply_to_id=None): """Sends an email to the given recipient. This function should be used for sending all user-facing emails. Raises an Exception if the sender_id is not appropriate for the given intent. Currently we support only system-generated emails and emails initiated by moderator actions. Args: recipient_id: str. The user ID of the recipient. sender_id: str. The user ID of the sender. intent: str. The intent string for the email, i.e. the purpose/type. email_subject: str. The subject of the email. email_html_body: str. The body (message) of the email. sender_email: str. The sender's email address. bcc_admin: bool. Whether to send a copy of the email to the admin's email address. sender_name: str or None. The name to be shown in the "sender" field of the email. reply_to_id: str or None. The unique reply-to id used in reply-to email address sent to recipient. """ if sender_name is None: sender_name = EMAIL_SENDER_NAME.value _require_sender_id_is_valid(intent, sender_id) recipient_email = user_services.get_email_from_user_id(recipient_id) cleaned_html_body = html_cleaner.clean(email_html_body) if cleaned_html_body != email_html_body: log_new_error( 'Original email HTML body does not match cleaned HTML body:\n' 'Original:\n%s\n\nCleaned:\n%s\n' % (email_html_body, cleaned_html_body)) return raw_plaintext_body = cleaned_html_body.replace('<br/>', '\n').replace( '<br>', '\n').replace('<li>', '<li>- ').replace('</p><p>', '</p>\n<p>') cleaned_plaintext_body = html_cleaner.strip_html_tags(raw_plaintext_body) if email_models.SentEmailModel.check_duplicate_message( recipient_id, email_subject, cleaned_plaintext_body): log_new_error( 'Duplicate email:\n' 'Details:\n%s %s\n%s\n\n' % (recipient_id, email_subject, cleaned_plaintext_body)) return def _send_email_in_transaction(): sender_name_email = '%s <%s>' % (sender_name, sender_email) email_services.send_mail( sender_name_email, recipient_email, email_subject, cleaned_plaintext_body, cleaned_html_body, bcc_admin, reply_to_id=reply_to_id) email_models.SentEmailModel.create( recipient_id, recipient_email, sender_id, sender_name_email, intent, email_subject, cleaned_html_body, datetime.datetime.utcnow()) return transaction_services.run_in_transaction(_send_email_in_transaction)