def set_password_link(email, subdomain, org, auth_token, member_name): from_email = settings.EMAIL_HOST_USER to = [email] subject = "Welcome Email" msg = MIMEMultipart('alternative') html_content = render_to_string( 'TFC/setpassword_link.html', { 'org': org, 'subdomain': subdomain, 'auth_token': auth_token, 'member_name': member_name }) msg = EmailMultiAlternatives(subject, html_content, from_email, [to]) msg.attach_alternative(html_content, "text/html") msg.send(fail_silently=True)
def screeninglink_mail(email, org, subdomain): volunteer = Candidate.objects.get(email=email) name = volunteer.name screening = Screenings.objects.create(candidate_id=volunteer) screeninguuid = screening.screening_uuid print(screeninguuid) email = volunteer.email from_email = settings.EMAIL_HOST_USER to = [email] subject = "Screening Link" msg = MIMEMultipart('alternative') html_content = render_to_string( 'TFC/email.html', { 'org': org, 'subdomain': subdomain, 'screeninguuid': screeninguuid, 'name': name }) msg = EmailMultiAlternatives(subject, html_content, from_email, [to]) msg.attach_alternative(html_content, "text/html") msg.send(fail_silently=True)
def send(): from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText msg = MIMEMultipart('alternative') if self.subject: msg['Subject'] = self.subject else: msg['Subject'] = 'No Subject' if self.friendly_to: msg[''] # Attach our text message msg.attach(MIMEText('text',self.text)) # Detect if there is HTML if self.html: msg.attach(MIMEText('html',self.html) _mailer(msg) part1 = MIMEText(text,'plain') part2 = MIMEText(html,'html') msg.attach(part1) msg.attach(part2) send(me,you,msg.as_string(),SERVER,USER,PASS) s = smtplib.SMTP(SERVER) s.starttls() s.login(USER,PASS) s.sendmail(me,you,msg) from django.template import Context, Template t = Template(message) c = Context() def send_mail_template(subject, template, addr_from, addr_to, context=None, attachments=None, fail_silently=False): """ Send email rendering text and html versions for the specified template name using the context dictionary passed in. Arguments are as per django's send_mail apart from template which should be the common path and name of the text and html templates without the extension, for example: "email_templates/contact" where both "email_templates/contact.txt" and "email_templates/contact.html" exist. """ from django.core.mail import EmailMultiAlternatives from django.template import loader, Context if context is None: context = {} if attachments is None: attachments = [] # allow for a single address to be passed in if not hasattr(addr_to, "__iter__"): addr_to = [addr_to] # loads a template passing in vars as context render = lambda type: loader.get_template("%s.%s" % (template, type)).render(Context(context)) # create and send email msg = EmailMultiAlternatives(subject, render("txt"), addr_from, addr_to) msg.attach_alternative(render("html"), "text/html") for attachment in attachments: msg.attach(attachment) msg.send(fail_silently=fail_silently)