def send_mail_as_noreply(address, subject, msg=None, html=None, attachments=None): logging.info(u"Sending email to %s: [%s] %s" % (address, subject, msg)) try: mail = EmailMessage() mail.sender = NO_REPLY_SENDER mail.to = address mail.subject = subject if attachments: mail.attachments = attachments if html: mail.html = html elif msg: mail.body = msg else: mail.body = "---" # mail.body cannot be empty string, raises exception mail.check_initialized() mail.send() except Exception, e: logging.error("Email sending failed: %s" % e.message)
def translate_message(self, msg): sender = msg.get_unixfrom() or msg['From'] if not sender: if self.fix_sender: sender = self.default_sender else: raise BadMessageError("No sender specified") to = msg['To'] if not to: raise BadMessageError("No destination addresses specified") message = EmailMessage(sender=sender or msg['From'], to=to) # Go through all the headers which Google will let us use cc = msg['Cc'] if cc: message.cc = cc bcc = msg['Bcc'] if bcc: message.bcc = cc reply_to = msg['Reply-To'] if reply_to: message.reply_to = reply_to subject = msg['Subject'] if subject: message.subject = subject # If there's just a plain text body, use that, otherwise # iterate over all the attachments payload = msg.get_payload(decode=True) if isinstance(payload, basestring): message.body = payload else: body = '' html = '' attachments = [] # GAE demands we specify the body explicitly - we use the first text/plain attachment we find. # Similarly, we pull in the first html we find and use that for message.html # We pull in any other attachments we find; but we ignore the multipart structure, # because GAE doesn't give us enough control there. for part in msg.walk(): if part.get_content_type() == 'text/plain' and not body: body = part.get_payload(decode=True) elif part.get_content_type() == 'text/html' and not html: html = part.get_payload(decode=True) elif not part.get_content_type().startswith('multipart'): attachments.append( (get_filename(part), part.get_payload(decode=True))) if not body: raise BadMessageError("No message body specified") message.body = body if html: message.html = html if attachments: message.attachments = attachments return message
def translate_message(self, msg): sender = msg.get_unixfrom() or msg["From"] if not sender: if self.fix_sender: sender = self.default_sender else: raise BadMessageError("No sender specified") to = msg["To"] if not to: raise BadMessageError("No destination addresses specified") message = EmailMessage(sender=sender or msg["From"], to=to) # Go through all the headers which Google will let us use cc = msg["Cc"] if cc: message.cc = cc bcc = msg["Bcc"] if bcc: message.bcc = cc reply_to = msg["Reply-To"] if reply_to: message.reply_to = reply_to subject = msg["Subject"] if subject: message.subject = subject # If there's just a plain text body, use that, otherwise # iterate over all the attachments payload = msg.get_payload(decode=True) if isinstance(payload, basestring): message.body = payload else: body = "" html = "" attachments = [] # GAE demands we specify the body explicitly - we use the first text/plain attachment we find. # Similarly, we pull in the first html we find and use that for message.html # We pull in any other attachments we find; but we ignore the multipart structure, # because GAE doesn't give us enough control there. for part in msg.walk(): if part.get_content_type() == "text/plain" and not body: body = part.get_payload(decode=True) elif part.get_content_type() == "text/html" and not html: html = part.get_payload(decode=True) elif not part.get_content_type().startswith("multipart"): attachments.append((get_filename(part), part.get_payload(decode=True))) if not body: raise BadMessageError("No message body specified") message.body = body if html: message.html = html if attachments: message.attachments = attachments return message
def send_activation_email(user): '''Send the welcome email''' e = EmailMessage() e.subject = "Welcome to Parabay." e.body = """ Hello, Thanks for signing up, please click the link below to download the Outlook plugin. %(url)s - Parabay team. """ % { 'email': user.email, 'url': '%s/%s' % ('http://parabayweb.appspot.com', 'app/ParabayOutlookSetup.msi') } e.sender = utils.SENDER_EMAIL e.to = user.email e.send()
def process_exception(self, request, exception): logging.exception('exception!') message = EmailMessage() message.sender = settings.DEFAULT_FROM_EMAIL message.to = [admin[1] for admin in settings.ADMINS] message.subject = 'exception at %s' % request.path message.body = """ URL: %(url)s Exception: %(traceback)s --- User: %(user)s Email: %(email)s --- REQUEST META: %(META)s """ % { 'url': request.build_absolute_uri(request.get_full_path()), 'traceback': traceback.format_exc(), 'user': request.user, 'email': request.user.email if request.user.is_authenticated() else None, 'META': request.META } message.check_initialized() message.send() return None
def get_second_trial_communication_email(account): """ prepare the invitation email message """ SUBJECT = "Foojal: Don't lose out." EMAIL_CONTENT = """ Hello %s Just checking to see how you are liking your Foojal.com trial subscription. Sign up today for a full year of Foojal.com for only $24.00 a year before we increase the price. That's only $2.00 a month. If you have any questions during your trial period, please email us; we would love to talk with you. Thank you, Kathy and Adam %s""" message = EmailMessage() message.sender = settings.SITE_EMAIL message.to = account.user.email() message.subject = SUBJECT message.body = EMAIL_CONTENT % (account.nickname, settings.SITE_EMAIL) return message
def send_admin_notification(subject, data): message = EmailMessage() message.sender = settings.SITE_EMAIL message.to = settings.ADMIN_EMAIL message.subject = subject message.body = data message.send()
def send_appengine_email(sender, recipient, subject, body_html, body_text): email = EmailMessage() email.sender = sender email.to = recipient email.subject = subject email.body = body_text email.html = body_html email.send()
def login(base_url, login_return_url): user = users.get_current_user() # The user value object (VO) contains login and logout URLs. # (With /gateway stripped out so that it returns to the SWF). urls = getUrls(base_url, login_return_url) user_vo = { 'login': urls['login'], 'logout': urls['logout'], 'auth': False } if user: # Add the user object to the user VO. user_vo['user'] = user user_vo['auth'] = True # Get the user's profile from the database profile = UserProfile.all().filter('user ='******'profile'] = { 'name': profile.name, 'url': profile.url, 'description': profile.description, 'key': str(profile.key()) } #logging.info('Profile name: %s' % profile.name) #logging.info('Profile url: %s' % profile.url) #logging.info('Profile description: %s' %profile.description) return user_vo
def make_mail_message(sender, to, subject, body): EMAIL_REGEX = re.compile(r"[^@]+@[^@]+\.[^@]+") email = None if EMAIL_REGEX.match(to): email = EmailMessage() email.sender = sender email.to = to email.subject = subject email.body = body email.check_initialized() return email
def _gae_send(self, sender, to, subject, body, html): from google.appengine.api.mail import EmailMessage message = EmailMessage() message.sender = sender message.subject = subject message.body = body message.html = html message.to = to try: message.send() except Exception as ex: logging.warning(ex, exc_info=ex)
def send_staff_notification_email(self, request_handler): # Super hacky to ask for request_handler but it works for now message = EmailMessage() if self.House == "Men's Christian Campus House": message.sender = "CCH Housing Application <*****@*****.**>" message.to = request_handler.settings.HousingApplicationCch_CompletionEmail message.subject = "CCH Housing Application (%s)" % self.FullName else: message.sender = "WCCH Housing Application <*****@*****.**>" message.to = request_handler.settings.HousingApplicationWcch_CompletionEmail message.subject = "WCCH Housing Application (%s)" % self.FullName message.html = self._generate_staff_notification_email_html() message.body = self._generate_staff_notification_email_text() message.send()
def send_applicant_notification_email(self): # Super hacky to ask for request_handler but it works for now message = EmailMessage() if self.House == "Men's Christian Campus House": message.sender = "CCH Housing Application <*****@*****.**>" message.to = self.EmailAddress message.subject = "Thank you for applying to the Rolla CCH!" else: message.sender = "WCCH Housing Application <*****@*****.**>" message.to = self.EmailAddress message.subject = "Thank you for applying to the Rolla WCCH!" message.html = self._generate_applicant_notification_email_html() message.body = self._generate_applicant_notification_email_text() message.send()
def _gae_send_mail(sender, to, cc=None, bcc=None, reply_to=None, subject='', body='', html='', attachments=[], headers={}): email = EmailMessage() email.sender = sender email.to = to email.subject = subject email.body = body if cc: email.cc = cc if bcc: email.bcc = bcc if reply_to: email.reply_to = reply_to if html: email.html = html if attachments: email.attachments = attachments if headers: email.headers = headers return email.send()
def updateProfile(profileVO): user = users.get_current_user() if user: # Does the profile already exist? if profileVO.key == None: # No, create a new profile. profile = UserProfile() #logging.info("Creating a new profile!") else: # Yes, get the existing profile from the data store. profile = UserProfile.get(profileVO.key) #logging.debug("Updating existing profile...") # Update and save the profile. profile.user = user profile.name = profileVO.name profile.url = profileVO.url try: profile.description = profileVO.description except AttributeError: #logging.info("Profile description was empty, so we're skipping it.") pass profile.save() # Inform the user via email that they've updated their profile email = EmailMessage() email.subject = "Your shiny new profile." email.body = """ Hello %(name)s, It's lovely to meet you. I've stored your profile safely in the bowels of the Googleplex. Name: %(name)s URL: %(url)s You are: %(description)s - The GAE SWF Robot (Alvin).""" % {'name': profile.name, 'url': profile.url, 'description': profile.description} email.sender = "*****@*****.**" email.to = user.email() email.send() return {'name': profile.name, 'url': profile.url, 'description': profile.description, 'key': profileVO.key} return False
def send_account_deleted(user): '''Send the account deleted email''' e = EmailMessage() e.subject = "Parabay - Account Deleted" e.body = """ Hello, Your account has been deleted. - Parabay team. """ % {'email': user.email} e.sender = utils.SENDER_EMAIL e.to = user.email e.send()
def send_password_reset(user, raw_password): '''Send the password reset email''' e = EmailMessage() e.subject = "Parabay - Password reset" e.body = """ Hello, Your password has been reset to '%(password)s'. - Parabay team. """ % {'email': user.email, 'password': raw_password} e.sender = utils.SENDER_EMAIL e.to = user.email e.send()
def contact_us(request): if request.method == "POST": form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data msg = EmailMessage() msg.sender = '*****@*****.**' msg.to = '*****@*****.**' msg.subject = cd['topic'] msg.body = "From " + cd['name'] + " at " + cd['email'] + " Message: " + cd['message'] #msg = "From " + cd['name'] + " at " + cd['email'] + " Message: " + cd['message'] #send_mail(cd['topic'], msg, cd['email'], ['*****@*****.**']) msg.send() return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm() return render_to_response('contact_form.html', { 'form' : form }, context_instance=RequestContext(request))
def send_staff_ref_notification_email(self, request_handler, ref_type): if ref_type not in ['c', 'o']: raise ValueError # Super hacky to ask for request_handler but it works for now message = EmailMessage() if self.House == "Men's Christian Campus House": message.sender = "CCH Housing Application <*****@*****.**>" message.to = request_handler.settings.HousingApplicationCch_CompletionEmail message.subject = "CCH Housing Reference (%s)" % self.FullName else: message.sender = "WCCH Housing Application <*****@*****.**>" message.to = request_handler.settings.HousingApplicationWcch_CompletionEmail message.subject = "WCCH Housing Reference (%s)" % self.FullName message.html = self._generate_staff_ref_notification_html(ref_type) message.body = self._generate_staff_ref_notification_text(ref_type) message.send()
def send_activation_email(user): '''Send the welcome email''' e = EmailMessage() e.subject = "Welcome to Parabay." e.body = """ Hello, Thanks for signing up, please click the link below to download the Outlook plugin. %(url)s - Parabay team. """ % {'email': user.email, 'url': '%s/%s' % ('http://parabayweb.appspot.com', 'app/ParabayOutlookSetup.msi')} e.sender = utils.SENDER_EMAIL e.to = user.email e.send()
def send(self): """ Build and send an email message from this model instance """ # create new email message new_email = EmailMessage() # set sender address new_email.sender = self.get_sender() # set to addresses new_email.to = self.to # set cc addresses if self.cc: new_email.cc = self.cc # set bcc addresses if self.bcc: new_email.bcc = self.bcc # set reply to address if self.reply_to: new_email.reply_to = self.reply_to else: new_email.reply_to = self.get_sender() # set email subject new_email.subject = self.subject # set plaintext body if self.body_plain: new_email.body = self.body_plain # set html body if self.body_html: new_email.html = self.body_html # check that the email has been properly initialized and send new_email.check_initialized() new_email.send()
def send_account_deleted(user): '''Send the account deleted email''' e = EmailMessage() e.subject = "Parabay - Account Deleted" e.body = """ Hello, Your account has been deleted. - Parabay team. """ % { 'email': user.email } e.sender = utils.SENDER_EMAIL e.to = user.email e.send()
def send(self): """Método que envia email para destinatário.""" email = EmailMessage() email.sender = '%s <%s>' % ("rlopes-blog", __email__) email.subject = 'Fale comigo - rlopes' email.to = __email__ email.body = """ Nome: %(nome)s Data Contato: %(data)s Email: %(email)s %(messagem)s """ % {'nome':self.nome.data, 'data':datetime.today().strftime('%d/%m/%Y'), 'messagem':self.mensagem.data, 'email':self.email.data} email.send()
def send_password_reset(user, raw_password): '''Send the password reset email''' e = EmailMessage() e.subject = "Parabay - Password reset" e.body = """ Hello, Your password has been reset to '%(password)s'. - Parabay team. """ % { 'email': user.email, 'password': raw_password } e.sender = utils.SENDER_EMAIL e.to = user.email e.send()
def get(self): errors = [] end = time.time() start = end - (24 * 60 * 60) for log in logservice.fetch(start_time=start, end_time=end, include_app_logs=True, minimum_log_level=logservice.LOG_LEVEL_ERROR): for app_log in log.app_logs: if app_log.level >= 3: errors.append(app_log.message.split('\n')[-1]) self.response.out.write("There are %s errors.<br />" % len(errors)) for e in errors: self.response.out.write(e + "<br />") if len(errors) > 0: message = EmailMessage() message.sender = "Rolla CCF Website Errors <*****@*****.**>" message.to = "*****@*****.**" message.subject = "CCF Website Errors (%s)" % len(errors) message.body = "\n".join(errors) message.send()
def get_first_trial_communication_email(account): """ prepare the invitation email message """ SUBJECT = "Foojal: First couple of days" EMAIL_CONTENT = """ Hello %s Just checking to see how you are liking your first few days of Foojal.com. If you have any questions during your trial period, please email us; we would love to talk with you. Your Team: %s""" message = EmailMessage() message.sender = settings.SITE_EMAIL message.to = account.user.email() message.subject = SUBJECT message.body = EMAIL_CONTENT % (account.nickname, settings.SITE_EMAIL) return message
def get_invitation_email(address, key): """ prepare the invitation email message """ EMAIL = "*****@*****.**" SUBJECT = "Your Foojal Invitation" URL = "http://app.foojal.com/invites/" EMAIL_CONTENT = """ You have been invited to Foojal.com! To accept this invitation, click the following link, or copy and paste the URL into your browser's address bar: %s""" message = EmailMessage() message.sender = EMAIL message.to = address message.subject = SUBJECT message.body = EMAIL_CONTENT % URL + key return message
def send_appengine_email(**kwargs): receiver = kwargs.get("receiver") sender = kwargs.get("sender", EmailManager.default_sender) subject = kwargs.get("subject") # email content text_template = kwargs.get("text_template") html_template = kwargs.get("html_template", "") # we must format the email address in this way receiver_address = "{0} <{1}>".format(receiver["name"], receiver["email"]) sender_address = "{0} <{1}>".format(sender["name"], sender["email"]) try: # create a new email object message = EmailMessage(sender=sender_address, to=receiver_address, subject=subject) # add the text body message.body = text_template if html_template: message.html = html_template if DEV: info(message.body) # send the email # on dev the email is not actually sent just logged in the terminal message.send() return True except Exception, e: warn(e) return False
def get_last_trial_communication_email(account): """ prepare the invitation email message """ SUBJECT = "Foojal: Your trial is over!" EMAIL_CONTENT = """ Hello %s We hope you liked your Foojal.com trial and that you will join us for a full year for only $24.00. To get a full year subscription to the best online photo food journal, go to your account page at http://app.foojal.com/account. If you have any questions, please email us; we would love to talk with you. Thank you, Kathy and Adam """ message = EmailMessage() message.sender = settings.SITE_EMAIL message.to = account.user.email() message.subject = SUBJECT message.body = EMAIL_CONTENT % account.nickname return message
def get(self): errors = [] end = time.time() start = end - (24 * 60 * 60) for log in logservice.fetch( start_time=start, end_time=end, include_app_logs=True, minimum_log_level=logservice.LOG_LEVEL_ERROR): for app_log in log.app_logs: if app_log.level >= 3: errors.append(app_log.message.split('\n')[-1]) self.response.out.write("There are %s errors.<br />" % len(errors)) for e in errors: self.response.out.write(e + "<br />") if len(errors) > 0: message = EmailMessage() message.sender = "Rolla CCF Website Errors <*****@*****.**>" message.to = "*****@*****.**" message.subject = "CCF Website Errors (%s)" % len(errors) message.body = "\n".join(errors) message.send()
def send_email(l): """Send an email notifying the recipient of l about their love.""" sender_future = l.sender_key.get_async() recipient_future = l.recipient_key.get_async() # Remove this love from recent_love if present (datastore is funny sometimes) recent_love = recent_received_love(l.recipient_key, limit=4).get_result() index_to_remove = None for i, love in enumerate(recent_love): if l.sender_key == love.sender_key and l.recipient_key == love.recipient_key and l.message == love.message: index_to_remove = i break if index_to_remove is not None: del recent_love[index_to_remove] sender = sender_future.get_result() recipient = recipient_future.get_result() email = EmailMessage() email.sender = config.LOVE_SENDER_EMAIL email.to = recipient.user.email() email.subject = u'Love from {}'.format(sender.full_name) email.body = u'"{}"\n\n{}'.format(l.message, '(Sent secretly)' if l.secret else '') email.html = render_template('email.html', love=l, sender=sender, recipient=recipient, recent_love_and_lovers=[ (love, love.sender_key.get()) for love in recent_love[:3] ]) email.send()
def send_reference_email(self, ref_type): # disable automatic references until we are ready return if ref_type not in ['c', 'o']: raise ValueError if ref_type == 'c': to_email = self.HomeChurchEmail else: to_email = self.OtherReferenceEmail if not to_email: return message = EmailMessage() message.sender = "Housing Application <*****@*****.**>" message.to = to_email if self.House == "Men's Christian Campus House": message.subject = "CCH Housing Application Reference for {name}".format(name=self.FullName) else: message.subject = "WCCH Housing Application Reference for {name}".format(name=self.FullName) message.html = self._generate_reference_email_html(ref_type) message.body = self._generate_reference_email_text(ref_type) message.send()