def contacto(request): if request.method == "POST": contact = ContactoForm(request.POST) mensaje_enviado = 'enviando/' if contact.is_valid(): c = contact.save(commit=False) c.save() to_mail = c.email subject, from_email, to = 'Copia Mensaje [email protected]', '*****@*****.**', to_mail, text_content = 'Gracias por inscribirte' html_content = '<h1>Copia del mensaje en [email protected]:</h1><br><p><strong>Mensaje: </strong><br>' + c.mensaje + '</p><br><p><strong>De: </strong>' + c.nombre + '(' + c.email + ')</p>' msg = EmailMultiAlternatives(subject, text_content, from_email, [to]) msg.attach_alternative(html_content, "text/html") msg.send() to_mail = '*****@*****.**' subject, from_email, to = 'Copia Mensaje [email protected]', '*****@*****.**', to_mail, text_content = 'Gracias por inscribirte' html_content = '<h1>Copia del mensaje en [email protected]:</h1><br><p><strong>Mensaje: </strong><br>' + c.mensaje + '</p><br><p><strong>De: </strong>' + c.nombre + '(' + c.email + ')</p>' msg = EmailMultiAlternatives(subject, text_content, from_email, [to]) msg.attach_alternative(html_content, "text/html") msg.send() print('Enviado :v') return redirect(mensaje_enviado) else: contact = ContactoForm() context = { 'form': contact, } return render(request, 'form_contacto.html', context)
def index(request): form = ContactoForm() if request.method == 'POST': form = ContactoForm(request.POST or NONE) if form.is_valid(): instance = form.save(commit=False) instance.save() to_mail = ['*****@*****.**'] subject = "Web Mail x" from_email = settings.DEFAULT_FROM_EMAIL context = { 'nombre': instance.nombre, 'email': instance.email, 'asunto': instance.asunto, 'mensaje': instance.mensaje } with open(settings.BASE_DIR + "/skeletonweb/templates/mail/contacto.txt") as f: signup_message = f.read() html_template = get_template("mail/contacto.html").render(context) message = EmailMultiAlternatives(subject=subject, body=signup_message, from_email=from_email, to=to_mail) message.attach_alternative(html_template, "text/html") message.send() messages.success(request, "Tu mensaje ha sido recibido") return redirect("/") context = {'form':form} return render(request,'index.html',context)
def contacto(request): if request.method == "POST": contact = ContactoForm(request.POST or None) enviando = '/enviando/' if contact.is_valid(): instance = contact.save(commit=False) instance.save() to_mail = [instance.email] subject = "Copia: Nuevo Mensaje | Murtao Web Mail" from_email = settings.DEFAULT_FROM_EMAIL context = { 'nombre': instance.nombre, 'apellido': instance.apellido, 'celular': instance.celular, 'email': instance.email, 'mensaje': instance.mensaje, 'fecha': instance.fecha, } with open(settings.BASE_DIR + "/templates/contactoapp/contacto_template_detail.txt" ) as f: signup_message = f.read() html_template = get_template( "contactoapp/contacto_template_detail.html").render(context) message = EmailMultiAlternatives(subject=subject, body=signup_message, from_email=from_email, to=to_mail) message.attach_alternative(html_template, "text/html") message.send() subject = "Copia: Nuevo Mensaje | Murtao Web Mail" from_email = settings.DEFAULT_FROM_EMAIL to_mail = ['*****@*****.**'] with open(settings.BASE_DIR + "/templates/contactoapp/contacto_template_detail.txt" ) as f: signup_message = f.read() html_template = get_template( "contactoapp/contacto_template_detail.html").render(context) message = EmailMultiAlternatives(subject=subject, body=signup_message, from_email=from_email, to=to_mail) message.attach_alternative(html_template, "text/html") message.send() return redirect(enviando) else: contact = ContactoForm() return contact
def index(request): projects = project.objects.all() servicio = Servicio.objects.all() contact_form = ContactoForm(data=request.POST) cotizacion = CotizacionForm(data=request.POST) if cotizacion.is_valid(): nombre_f = request.POST.get('nombre_c', '') apellido_f = request.POST.get('apellido', '') rut_f = request.POST.get('rut', '') empresa_f = request.POST.get('empresa', '') email_f = request.POST.get('email_c', '') servicio_f = request.POST.get('servicio', '') telefono_f = request.POST.get('telefono', '') try: b = Cliente(rut=rut_f, nombre=nombre_f, apellido=apellido_f, correo=email_f, telefono=telefono_f, empresa=empresa_f) c = Cotizacion(cliente=b, servicio=servicio_f, estado=False) b.save() c.save() return redirect(reverse('home')) except: return redirect(reverse('home')) if contact_form.is_valid(): nombre = request.POST.get('nombre', '') email = request.POST.get('email', '') asunto = request.POST.get('asunto', '') mensaje = request.POST.get('mensaje', '') #Enviar Correo email = EmailMessage("Consulta: " + asunto, "De {} <{}\n\nEscribio:\n\n{}".format( nombre, email, mensaje), "no-contestar", ["*****@*****.**"], reply_to=[email]) try: email.send() return redirect(reverse('home')) except: #Algo no ha ido bien return redirect(reverse('home')) return render( request, "base/index.html", { 'projects': projects, 'form': contact_form, 'servicios': servicio, 'form_c': cotizacion })