def send_submission_notification_email(self): """Sends an email notification This is used in the GDC to notify the user services team about submitting a project """ from_addr = self.app_config.get('EMAIL_FROM_ADDRESS') to_addr = self.app_config.get('EMAIL_SUPPORT_ADDRESS') preformatted = self.app_config.get('EMAIL_NOTIFICATION_SUBMISSION') subject = ( "[SUBMISSION] Project {project_id} has been submitted by {user}". format(project_id=self.project_id, user=self.user.username)) number_of_cases = 0 number_of_submitted_files = 0 experimental_strategies = set() for entity in self.entities: if entity.node.label == 'case': number_of_cases += 1 if utils.is_node_file(entity.node): ex_strategy = entity.node.props.get('experimental_strategy') if ex_strategy: experimental_strategies.add(ex_strategy) # Construct body text_body = preformatted.format( project_id=self.project_id, user_id=self.user.username, number_of_cases=number_of_cases, number_of_submitted_files=number_of_submitted_files, experimental_strategies=','.join(experimental_strategies), ) # Construct email envelope = envelopes.Envelope( from_addr=from_addr, to_addr=to_addr, subject=subject, text_body=text_body, ) description = "email '{}' to {}".format(subject, to_addr) self.logger.info("Sending " + description) # Send email (synchronous) connection = envelopes.SMTP(**self.smtp_conf) connection.send(envelope) self.logger.info("Sent " + description)
def send_async_email(app, toaddr, body): with app.app_context(): conn = envelopes.SMTP(host=current_app.config['MAIL_HOST'], port=current_app.config['MAIL_PORT'], login=current_app.config['MAIL_LOGIN'], password=current_app.config['MAIL_PASSWORD'], tls=False, timeout=None) envelope = envelopes.envelope.Envelope(to_addr=toaddr, from_addr=current_app.config['FROM_ADDR'], subject=current_app.config['REG_SUBJECT'], bcc_addr=current_app.config['ADMIN_EMAIL'], charset='utf-8', text_body=body) conn.send(envelope)
def __init__(self, *args, **kwargs): self.smtp = envelopes.SMTP(host="127.0.0.1") self.envelopes_to_send = list()