def send_msg(self, from_addr, to_addrs, msg, type): ''' Send message and return the list of email addresses sent ''' User = Pool().get('res.user') if not to_addrs: return to_addrs to_addrs = list(set(to_addrs)) users = User.search([ ('email', 'in', to_addrs), ]) for user in users: if not getattr(user, 'calendar_email_notification_' + type): to_addrs.remove(user.email) success = False try: server = get_smtp_server() server.sendmail(from_addr, to_addrs, msg.as_string()) server.quit() success = to_addrs except Exception: logging.getLogger('calendar_scheduling').error( 'Unable to deliver scheduling mail for %s' % self) return success
def send_confirmation_email(self, silent=True): """An email confirming that the order has been confirmed and that we are waiting for the payment confirmation if we are really waiting for it. For setting a convention this email has to be sent by rendering the templates * Text: `emails/sale-confirmation-text.jinja` * HTML: `emails/sale-confirmation-html.jinja` """ try: email_message = render_email( CONFIG['smtp_from'], self.party.email, 'Order Completed', text_template='emails/sale-confirmation-text.jinja', html_template='emails/sale-confirmation-html.jinja', sale=self ) server = get_smtp_server() server.sendmail( CONFIG['smtp_from'], [self.party.email], email_message.as_string() ) server.quit() except Exception, exc: if not silent: raise current_app.logger.error(exc)
def send_confirmation_email(self): """An email confirming that the order has been confirmed and that we are waiting for the payment confirmation if we are really waiting for it. For setting a convention this email has to be sent by rendering the templates * Text: `emails/sale-confirmation-text.jinja` * HTML: `emails/sale-confirmation-html.jinja` """ email_message = render_email( CONFIG['smtp_from'], self.invoice_address.email, 'Order Completed', text_template = 'emails/sale-confirmation-text.jinja', html_template = 'emails/sale-confirmation-html.jinja', sale = self ) server = get_smtp_server() server.sendmail( CONFIG['smtp_from'], [self.invoice_address.email], email_message.as_string() ) server.quit()
def validate(cls, records_mail): """Check before saving if the field mail is selected(True) and send in this case the entered values via mail to the lecturer. The email will be send to all email addresses which are saved for the lecturer in party.contact_mechanism""" super(Hshn, cls) pool = Pool() model = pool.get('party.contact_mechanism') try: server = get_smtp_server() except : pass # get the record row = records_mail # Read in the mail content mail_content = {} file = open(MAIL_FILE_PATH) for line in file: try: name, var = line.partition('=') except ValueError: continue mail_content[name.strip()] = var # send a mail row = row[0] if row.mail is True: # set the spo if row.spo_selection == 'SPO3': project_study = row.project_study_spo3 else: project_study = row.project_study_spo4 # get the party of the selected lecturer records_contact = model.search([('party', '=', row.lecturer)]) # send a mail to each mail address which is saved for the lecturer for row2 in records_contact: if row2.type == 'email': try: server.sendmail(mail_content['mail_address'], row2.value, mail_content['mail_message1'] + str(row.lecturer.name) + mail_content['mail_message2'] + '\n'+cls.topic.string+': ' + str(row.topic) + '\n'+cls.description.string+': ' + str(row.description) + '\n' + str(row.spo_selection) + mail_content['mail_message3'] + str(project_study)) except: pass # set mail to false row.mail = False
def send_all(cls): """ Sends emails with the default SMTP server and marks them as sent. """ server = get_smtp_server() for mail in cls.search([('state', '=', 'outbox')]): mail.send(server) server.quit()
def validate(cls, records_mail): """Check before saving if the field mail is selected(True) and send in this case the entered values via mail to the lecturer. The email will be send to all email addresses which are saved for the lecturer in party.contact_mechanism""" super(Hshn, cls) pool = Pool() model = pool.get('party.contact_mechanism') try: server = get_smtp_server() except : pass # get the record row = records_mail # Read in the mail content mail_content = {} file = open('../trytond/modules/hshn/mail.txt') for line in file: try: name, var = line.partition('=') except ValueError: continue mail_content[name.strip()] = var return # send a mail if row.mail is True: # set the spo if row.spo_selection == 'SPO3': project_study = row.project_study_spo3 else: project_study = row.project_study_spo4 # get the party of the selected lecturer records_contact = model.search([('party', '=', row.lecturer)]) # send a mail to each mail address which is saved for the lecturer for row2 in records_contact: if row2.type == 'email': try: server.sendmail(mail_content['mail_address'], row2.value, mail_content['mail_message1'] + str(row.lecturer.name) + mail_content['mail_message2'] + '\n'+cls.topic.string+': ' + str(row.topic) + '\n'+cls.description.string+': ' + str(row.description) + '\n' + str(row.spo_selection) + mail_content['mail_message3'] + str(project_study)) except: pass # set mail to false row.mail = False
def send_msg(from_addr, to_addr, msg, task_number): success = False try: server = get_smtp_server() server.sendmail(from_addr, [to_addr], msg.as_string()) server.quit() success = True except Exception: logger.error("Unable to deliver email for task '%s'" % (task_number)) return success
def send_notification_mail(self): """ Send a notification mail to sales department and thank you email to lead whenever new opportunity is created. """ Config = Pool().get('sale.configuration') sale_config = Config(1) # Prepare the content for email for lead lead_receivers = [self.party.email] lead_message = render_email( from_email=sale_config.sale_opportunity_email, to=', '.join(lead_receivers), subject="Thank You for your query", text_template='crm/emails/lead_thank_you_mail.jinja', lead=self ) # Prepare the content for email for sale department sale_subject = "[Openlabs CRM] New lead created by %s" % \ (self.party.name) sale_receivers = [ member.email for member in self.company.sales_team if member.email ] sender = config.get('email', 'from') sale_message = render_email( from_email=sender, to=', '.join(sale_receivers), subject=sale_subject, text_template='crm/emails/sale_notification_text.jinja', lead=self ) # Send mail. server = get_smtp_server() if sale_receivers: # Send to sale department server.sendmail( sender, sale_receivers, sale_message.as_string() ) if lead_receivers: # Send to lead server.sendmail( sender, lead_receivers, lead_message.as_string() ) server.quit()
def send_msg(self, from_addr, to_addr, msg): ''' Send message and return True if the mail has been sent ''' success = False try: server = get_smtp_server() server.sendmail(from_addr, to_addr, msg.as_string()) server.quit() success = True except Exception: logging.getLogger('calendar_scheduling').error( 'Unable to deliver reply mail for %s' % self) return success
def send_reset_email(self): """ Send an account reset email to the user :param nereid_user: The browse record of the user """ email_message = render_email(CONFIG['smtp_from'], self.email, _('Account Password Reset'), text_template='emails/reset-text.jinja', html_template='emails/reset-html.jinja', nereid_user=self) server = get_smtp_server() server.sendmail(CONFIG['smtp_from'], [self.email], email_message.as_string()) server.quit()
def send_email(self, email_id): """ Send out the given email using the SMTP_CLIENT if configured in the Tryton Server configuration :param email_id: ID of the email to be sent """ email_obj = Pool().get('electronic_mail') email_record = email_obj.browse(email_id) recepients = recepients_from_fields(email_record) server = get_smtp_server() server.sendmail(email_record.from_, recepients, email_obj._get_email(email_record)) server.quit() return True
def send_reset_email(self, nereid_user): """ Send an account reset email to the user :param nereid_user: The browse record of the user """ email_message = render_email( CONFIG["smtp_from"], nereid_user.email, _("Account Password Reset"), text_template="emails/reset-text.jinja", html_template="emails/reset-html.jinja", nereid_user=nereid_user, ) server = get_smtp_server() server.sendmail(CONFIG["smtp_from"], [nereid_user.email], email_message.as_string()) server.quit()
def send_activation_email(self, nereid_user): """ Send an activation email to the user :param nereid_user: The browse record of the user """ email_message = render_email( CONFIG['smtp_from'], nereid_user.email, _('Account Activation'), text_template = 'emails/activation-text.jinja', html_template = 'emails/activation-html.jinja', nereid_user = nereid_user ) server = get_smtp_server() server.sendmail( CONFIG['smtp_from'], [nereid_user.email], email_message.as_string() ) server.quit()
def send_reset_email(self): """ Send an account reset email to the user :param nereid_user: The browse record of the user """ email_message = render_email( CONFIG['smtp_from'], self.email, _('Account Password Reset'), text_template='emails/reset-text.jinja', html_template='emails/reset-html.jinja', nereid_user=self ) server = get_smtp_server() server.sendmail( CONFIG['smtp_from'], [self.email], email_message.as_string() ) server.quit()
def notify_expiration(): logging.debug('Checking PEFC certificate for notification') pool = Pool() Lang = pool.get('ir.lang') PEFC = pool.get('pefc.pefc') pefcs = PEFC.search([ ('enabled', '=', True), ]) PEFCNotifyRecipient = Pool().get('pefc.pefc_notify_recipient') for pefc in pefcs: month = timedelta(days=30) expiration = pefc.date + (pefc.duration * month) if (expiration - month) != date.today() and \ (expiration - (2 * month)) != date.today(): continue months = (expiration - date.today()).days / 30 for notif in PEFCNotifyRecipient.search([('sender', '!=', None)]): lang = notif.recipient.lang if not lang: lang, = Lang.search([('code', '=', 'en_US')], limit=1) args = { 'company': pefc.party.name, 'months': months, } with Transaction().set_context(language=lang.code): subject = notif.msg_subject % args content = notif.msg_content % args sender = notif.sender.email recipient = notif.recipient.email msg = Message() msg.set_payload(content, 'utf-8') msg.add_header('To', recipient) msg.add_header('From', sender) msg.add_header('Subject', subject) server = get_smtp_server() server.sendmail(sender, [recipient], msg.as_string()) server.quit() logging.debug('Sent PEFC notification mail about %s to %s', pefc.party.name, recipient)
def test_0005_mock_setup(self): assert get_smtp_server() is self.PatchedSMTP.return_value
def invitation_new_user_handler(nereid_user_id): """When the invite is sent to a new user, he is sent an invitation key with the url which guides the user to registration page This method checks if the invitation key is present in the url If yes, search for the invitation with this key, attache the user to the invitation and project to the user If not, perform normal operation """ try: Invitation = Pool().get('project.work.invitation') Project = Pool().get('project.work') NereidUser = Pool().get('nereid.user') Activity = Pool().get('nereid.activity') except KeyError: # Just return silently. This KeyError is cause if the module is not # installed for a specific database but exists in the python path # and is loaded by the tryton module loader warnings.warn( "nereid-project module installed but not in database", DeprecationWarning, stacklevel=2 ) return invitation_code = request.args.get('invitation_code') if not invitation_code: return invitation, = Invitation.search([ ('invitation_code', '=', invitation_code) ], limit=1) if not invitation: return Invitation.write([invitation], { 'nereid_user': nereid_user_id, 'invitation_code': None }) nereid_user = NereidUser(nereid_user_id) subject = '[%s] %s Accepted the invitation to join the project' \ % (invitation.project.rec_name, nereid_user.display_name) receivers = [ m.email for m in invitation.project.members if m.user.email and m.role == 'admin' ] email_message = render_email( text_template='project/emails/invite_2_project_accepted_text.html', subject=subject, to=', '.join(receivers), from_email=CONFIG['smtp_from'], invitation=invitation ) server = get_smtp_server() server.sendmail(CONFIG['smtp_from'], receivers, email_message.as_string()) server.quit() Project.write( [invitation.project], { 'members': [ ('create', [{ 'user': [nereid_user_id] }]) ] } ) Activity.create([{ 'actor': nereid_user_id, 'object_': 'project.work, %d' % invitation.project.id, 'verb': 'joined_project', 'project': invitation.project.id, }])
def send_email(self, invoice, file_data, filename, voucher_data=None, voucher_filename=None): "send_email" from_addr = invoice.company.party.email periodo = invoice.invoice_date.strftime("%m-%Y") code = "" if not from_addr: return to_addrs = [] if hasattr(self.start, 'to_addr') and self.start.to_addr.value: to_addrs = [self.start.to_addr.value] code = invoice.party.name # creo el mensaje outer = MIMEMultipart() outer['Subject'] = '%s: Factura Electronica' \ % invoice.company.party.name html = self.get_text_solicitud(code, periodo, invoice) outer['From'] = from_addr outer['To'] = ', '.join(to_addrs) outer['Date'] = eutils.formatdate() part2 = MIMEText(html, 'html', 'utf-8') outer.attach(part2) ctype = "application/octet-stream" maintype, subtype = ctype.split("/", 1) attachment = MIMEBase(maintype, subtype) attachment.set_payload(file_data) # Encode the payload using Base64 encoders.encode_base64(attachment) # Set the filename parameter attachment.add_header("Content-Disposition", "attachment", filename=filename) outer.attach(attachment) if voucher_data: attachment = MIMEBase(maintype, subtype) attachment.set_payload(voucher_data) # Encode the payload using Base64 encoders.encode_base64(attachment) # Set the filename parameter attachment.add_header("Content-Disposition", "attachment", filename=voucher_filename) outer.attach(attachment) try: server = get_smtp_server() server.sendmail(from_addr, to_addrs, outer.as_string()) logger.info('sending invoice to %s' % ''.join(to_addrs)) server.quit() except Exception, e: logger.error('SendInvoices when sending invoice to client %s', to_addrs, exc_info=True) raise Exception(str(e))