def post(self): # retrieve email details from post body sender = self.request.get('sender', default_value=None) to = self.request.get('to', default_value=[]) reply_to = self.request.get('reply_to', default_value=None) subject = self.request.get('subject', default_value=None) body_plain = self.request.get('body_plain', default_value=None) body_html = self.request.get('body_html', default_value=None) # build email model and save/send new_email = Email( sender=sender, to=[to], reply_to=reply_to, subject=subject, body_plain=body_plain, body_html=body_html, ) new_email.put() # build and return response object response = new_email.get_json(encode=False) return self.json_response(response)
def send_contact_email(toEmail, fromEmail, subject, message): send_mail(subject, message, fromEmail, toEmail, fail_silently=False) email = Email(to_email=toEmail, from_email=fromEmail, subject=subject, message=message, email_type=CONTACT_EMAIL) email.save() return
def send_post_verification_email(url, userEmail, postType): sub = SUBJECT_MAPPINGS.get(postType) context = {"url" : url, "object" : POST_MAPPINGS.get(postType)} msg = render_to_string('mailer/postTemplate.txt', context) fromEmail = settings.FROM_EMAIL send_mail(sub, msg, fromEmail, [userEmail], fail_silently=False) email = Email(to_email=userEmail, from_email=fromEmail,subject=sub,message=msg,email_type=SIGNUP_VERIFY) email.save() return
def send_signup_verification_email(url, userEmail, firstname): sub = SUBJECT_MAPPINGS.get('signup') context = {"url": url, "firstname": firstname} msg = render_to_string('mailer/signupTemplate.txt', context) fromEmail = settings.FROM_EMAIL send_mail(sub, msg, fromEmail, [userEmail], fail_silently=False) email = Email(to_email=userEmail, from_email=fromEmail,subject=sub,message=msg,email_type=SIGNUP_VERIFY) email.save() return
def send_survey_email(url, userEmail): sub = SUBJECT_MAPPINGS.get('survey') context = {"url" : url} msg = render_to_string('mailer/surveyTemplate.txt', context) fromEmail = settings.FROM_EMAIL send_mail(sub, msg, fromEmail, [userEmail], fail_silently=False) email = Email(to_email=userEmail, from_email=fromEmail,subject=sub,message=msg,email_type=SIGNUP_VERIFY) email.save() return
def send_post_verification_email(url, userEmail, postType): sub = SUBJECT_MAPPINGS.get(postType) context = {"url": url, "object": POST_MAPPINGS.get(postType)} msg = render_to_string('mailer/postTemplate.txt', context) fromEmail = settings.FROM_EMAIL send_mail(sub, msg, fromEmail, [userEmail], fail_silently=False) email = Email(to_email=userEmail, from_email=fromEmail, subject=sub, message=msg, email_type=SIGNUP_VERIFY) email.save() return
def send_signup_verification_email(url, userEmail, firstname): sub = SUBJECT_MAPPINGS.get('signup') context = {"url": url, "firstname": firstname} msg = render_to_string('mailer/signupTemplate.txt', context) fromEmail = settings.FROM_EMAIL send_mail(sub, msg, fromEmail, [userEmail], fail_silently=False) email = Email(to_email=userEmail, from_email=fromEmail, subject=sub, message=msg, email_type=SIGNUP_VERIFY) email.save() return
def send_survey_email(url, userEmail): sub = SUBJECT_MAPPINGS.get('survey') context = {"url": url} msg = render_to_string('mailer/surveyTemplate.txt', context) fromEmail = settings.FROM_EMAIL send_mail(sub, msg, fromEmail, [userEmail], fail_silently=False) email = Email(to_email=userEmail, from_email=fromEmail, subject=sub, message=msg, email_type=SIGNUP_VERIFY) email.save() return
def initialize_mailing(template_email_id, organizationelection_id, priority): """Hey fa""" source_email = Email.objects.select_related('mailingtemplate').get( id=template_email_id) source_org_election = OrganizationElection.objects.select_related( 'organization', 'organization__from_address').get(pk=organizationelection_id) source_blocks = source_email.blocks.only('id') source_categories = source_email.categories.only('id') new_email = Email(organization=source_org_election.organization, subject=source_email.subject, pre_header=source_email.pre_header, from_name=source_email.from_name, body_above=source_email.body_above, body_below=source_email.body_below) new_email.save() new_email.blocks.set(source_blocks) new_email.categories.set(source_categories) new_mailing = Mailing( email=new_email, template=source_email.mailingtemplate, organization_election=source_org_election, from_email=source_org_election.organization.from_address.address, source=generate_source(new_email), status='pending') new_mailing.save() initialize_recipients.apply_async(kwargs={ 'email_id': new_email.id, 'organizationelection_id': source_org_election.id, 'priority': priority }, priority=priority) logger.info(u'Mailing Initalized. Email %s OElection %s Org %s', new_mailing.pk, source_org_election.id, source_org_election.organization_id) newrelic.agent.add_custom_parameter('email_id', new_email.pk) newrelic.agent.add_custom_parameter('organization_id', source_org_election.organization_id)
def mail(request): """ Renders the email sending page. On a GET request: Shows only name of patients who have an email ID. On a POST request: Gets data from the submitted form and sends email. If attachment is found, it is sent along, else not. """ if request.method == 'GET': # Request the API. req = requests.get(api_endpoint + "patients") # Store detail of each patient if email is present. email_patients = [one_patient for one_patient in req.json()["items"] if \ one_patient['email']] patient_names = [one_patient[u'name'] for one_patient in email_patients] patient_emails = [one_patient[u'email'] for one_patient in email_patients] # Defining dictionary to render template. context = {'total_patients_having_email': range(len(email_patients)), 'patient_names': patient_names, 'patient_emails': patient_emails } return render(request, 'mail.html', context) if request.method == 'POST': # Get data from POST request. subject = request.POST['subject'] message = request.POST['message'] email = request.POST['email'] patient_email = request.POST.getlist('patientcheck') # Object for sending email meassages. email_object = EmailMessage( subject, message, email, patient_email, ) if request.FILES: # If attachment is found, attach file to object. file_name = request.FILES['attachment'].name file_data = request.FILES['attachment'].read() email_object.attach(file_name,file_data) email_data = Email(mail_content=message, mail_users=json.dumps(patient_email), mail_subject=subject, mail_attachment=request.FILES['attachment'], ) else: # Else, send the text only. email_data = Email(mail_content=message, mail_users=json.dumps(patient_email), mail_subject=subject, ) # Send the email. email_object.send() # Save the email data. email_data.save() # Redirect to home page. return HttpResponseRedirect('/?q=Mail Sent.')
def send(self): msg = Email(subject=self.subject, body=self.text_content, html=self.html_content, user=self.user, recipient=self.to, from_address=self.from_address, headers = self.headers) msg.send(self.update_next_email_time)
def send_contact_email(toEmail, fromEmail, subject, message): send_mail(subject, message, fromEmail, toEmail, fail_silently=False) email = Email(to_email=toEmail , from_email=fromEmail,subject=subject,message=message,email_type=CONTACT_EMAIL) email.save() return