def send_invites_success(self, appstruct): settings = self.request.registry.settings mailer = Mailer( host=settings['mail.host'], port=settings['mail.port'], username=settings['bimt.referrals_mail_username'], password=settings['bimt.referrals_mail_password'], tls=True, default_sender=settings['bimt.referrals_mail_sender'], ) emails = appstruct['emails'].splitlines() for email in emails: mailer.send( Message( subject=u'Your friend, {}, gave you exclusive access to {}' .format( # noqa self.request.user.fullname, settings['bimt.app_title']), recipients=[ email, ], html=render('pyramid_bimt:templates/referral_email.pt', {'request': self.request}), ), ) self.request.registry.notify( ReferralEmailSent(self.request, self.request.user, 'Referral email sent to: {}'.format(email))) self.request.session.flash(u'Referral email sent to: {}'.format( ', '.join(appstruct['emails'].splitlines()))) return HTTPFound(location=self.request.route_path('referrals'))
class ThreadMailer(threading.Thread): """ 인덱스 추가/삭제를 위한 쓰레드 """ def __init__(self): threading.Thread.__init__(self) self.queue = Queue.Queue() self.mailer = Mailer(host="localhost") def send(self, msg): self.queue.put(msg) def run(self): while True: # 큐에서 작업을 하나 가져온다 msg = self.queue.get() self.mailer.send(msg) log.info(msg.subject) transaction.commit() log.info("MAIL COMMITTED!") # 작업 완료를 알리기 위해 큐에 시그널을 보낸다. self.queue.task_done() def end(self): self.queue.join()
def home_view(request): mailer = Mailer() message = Message(subject="測試信件", sender="*****@*****.**", recipients=['*****@*****.**'], body="這是測試信") mailer.send(message) return {}
def test_send(self): from pyramid_mailer.mailer import Mailer from pyramid_mailer.message import Message mailer = Mailer() msg = Message(subject="testing", sender="*****@*****.**", recipients=["*****@*****.**"], body="test") mailer.send(msg)
def test_send(self): from pyramid_mailer.mailer import Mailer from pyramid_mailer.message import Message mailer = Mailer() msg = Message(subject="testing", sender="*****@*****.**", recipients=["*****@*****.**"], body="test") mailer.send(msg)
def test_send_without_body(self): from pyramid_mailer.message import Message from pyramid_mailer.mailer import Mailer from pyramid_mailer.exceptions import InvalidMessage msg = Message(subject="testing", sender="*****@*****.**", recipients=["*****@*****.**"]) mailer = Mailer() self.assertRaises(InvalidMessage, mailer.send, msg) msg.html = "<b>test</b>" mailer.send(msg)
def test_send_without_body(self): from pyramid_mailer.message import Message from pyramid_mailer.mailer import Mailer from pyramid_mailer.exceptions import InvalidMessage msg = Message(subject="testing", sender="*****@*****.**", recipients=["*****@*****.**"]) mailer = Mailer() self.assertRaises(InvalidMessage, mailer.send, msg) msg.html = "<b>test</b>" mailer.send(msg)
def test_send(self): from pyramid_mailer.mailer import Mailer from pyramid_mailer.message import Attachment from pyramid_mailer.message import Message mailer = Mailer() msg = Message(subject="testing", sender="*****@*****.**", recipients=["*****@*****.**"], body="test") msg.attach(Attachment('test.txt', data=b"this is a test", content_type="text/plain")) mailer.send(msg)
def contato(request): """Contato""" # Import smtplib for the actual sending function import smtplib esquema = FormContato().bind(request=request) esquema.title = "Entre em contato com o Cuidando" form = deform.Form(esquema, buttons=('Enviar',)) if 'Enviar' in request.POST: # Validação do formulário try: form.validate(request.POST.items()) except deform.ValidationFailure as e: return {'form': e.render()} #sender = request.POST.get("email") #receivers = ['*****@*****.**'] #message = request.POST.get("assunto") try: #s = smtplib.SMTP( [host [, port [, local_hostname]]] ) #s = smtplib.SMTP('pop.mail.yahoo.com.br',587) #smtpObj.sendmail(sender, receivers, message) #s.quit() #mailer = get_mailer(request) mailer = Mailer() message = Message( subject=request.POST.get("assunto"), sender= request.POST.get("email"), #"*****@*****.**", recipients=['*****@*****.**'], body=request.POST.get("mensagem") ) mailer.send(message) transaction.commit() print "Successfully sent email" #except SMTPException: except: print "Error: unable to send email" return HTTPFound(location=request.route_url('inicial')) else: # Apresentação do formulário return {'form': form.render()}
def test_bcc_without_recipients(self): from pyramid_mailer.message import Message from pyramid_mailer.mailer import Mailer msg = Message(subject="testing", sender="*****@*****.**", body="testing", bcc=["*****@*****.**"]) mailer = Mailer() msgid = mailer.send(msg) response = msg.to_message() self.assertFalse("Bcc: [email protected]" in text_type(response)) self.assertTrue(msgid)
def send_mail(request): mailer = Mailer( host='smtp.gmail.com', port=587, #??? username='******', password='******', tls=True) if request.params.get('email') is not None: email = request.params['email'] else: email = "the email does not exist" send_topic = 'Welcome to join us for the seminar' send_er = '*****@*****.**' send_to = [email] send_this = "Thank you for signing up at our website..." message = Message( subject = send_topic, sender = send_er, recipients = send_to, body = send_this ) here = os.path.dirname(__file__) att1 = os.path.join(here, 'static','velur1.pdf') attachment = Attachment(att1, "image/jpg", open(att1, "rb")) message.attach(attachment) here = os.path.dirname(__file__) att2 = os.path.join(here, 'static','velur2.pdf') attachment = Attachment(att2, "image/jpg", open(att2, "rb")) message.attach(attachment) # mailer.send_immediately(message, fail_silently=False) mailer.send(message) return Response(email)
def send_mail(request): mailer = Mailer( host='smtp.gmail.com', port=587, #??? username='******', password='******', tls=True) if request.params.get('email') is not None: email = request.params['email'] else: email = "the email does not exist" send_topic = 'Welcome to join us for the seminar' send_er = '*****@*****.**' send_to = [email] send_this = "Thank you for signing up at our website..." message = Message(subject=send_topic, sender=send_er, recipients=send_to, body=send_this) attachment = Attachment("velur1.pdf", "image/jpg", open("velur1.pdf", "rb")) message.attach(attachment) attachment = Attachment("velur2.pdf", "image/jpg", open("velur2.pdf", "rb")) message.attach(attachment) # mailer.send_immediately(message, fail_silently=False) mailer.send(message) return Response(email)
def test_cc_without_recipients(self): from pyramid_mailer.message import Message from pyramid_mailer.mailer import Mailer msg = Message(subject="testing", sender="*****@*****.**", body="testing", cc=["*****@*****.**"]) mailer = Mailer() msgid = mailer.send(msg) response = msg.to_message() self.assertTrue("Cc: [email protected]" in text_type(response)) self.assertTrue(msgid)
def send_mail(request): mailer = Mailer( host='smtp.gmail.com', port=587, #??? username='******', password='******', tls=True) if request.params.get('email') is not None: email = request.params['email'] else: email = "the email does not exist" send_topic = 'Welcome to join us for the seminar' send_er = '*****@*****.**' send_to = [email] send_this = "Thank you for signing up at our website..." message = Message( subject = send_topic, sender = send_er, recipients = send_to, body = send_this ) attachment = Attachment("velur1.pdf", "image/jpg", open("velur1.pdf", "rb")) message.attach(attachment) attachment = Attachment("velur2.pdf", "image/jpg", open("velur2.pdf", "rb")) message.attach(attachment) # mailer.send_immediately(message, fail_silently=False) mailer.send(message) return Response(email)