def email(subject=None, recipients=None, body=None): mailer = Mailer(host='192.168.101.5') message = Message(subject=subject, sender='*****@*****.**', recipients=recipients, html=body) mailer.send_immediately(message)
def test_send_immediately_and_fail_silently(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_immediately(msg, True)
def profile(request): """ View profile page. """ user = User.get(request.session['login']) if request.method =='POST': flashError = "Sorry dude : wrong password" if not request.POST['initPassword'].strip(): request.session.flash('No password provided') return {'user':user} elif not bcrypt.hashpw(request.POST['initPassword'].encode('utf-8'), user.password) == user.password: request.session.flash(flashError) return {'user':user} if request.POST['submitDelete']: mailer = Mailer() message = Message(subject="Account deleted", sender=settings['mail_from'], recipients=[user.mail], body="Your account have been deleted") mailer.send_immediately(message, fail_silently=False) user.delete() request.session.delete() return HTTPFound(location=request.route_path('home')) if request.POST['newPassword'].strip(): if request.POST['newPassword'] == request.POST['confirmPassword']: password = bcrypt.hashpw(request.POST['newPassword'].encode('utf-8'), bcrypt.gensalt()) user.password = password else: request.session.flash(u"Password not confirm") return {'user' : user} user.name = request.POST['name'] user.description = request.POST['description'] user.mail = request.POST['email'] user.save() request.session.flash(u"Modification saved !") return {'user':user}
def test_send_immediately_multipart(self): from pyramid_mailer.mailer import Mailer from pyramid_mailer.message import Message mailer = Mailer() utf_8_encoded = b('mo \xe2\x82\xac') utf_8 = utf_8_encoded.decode('utf_8') text_string = utf_8 html_string = '<p>'+utf_8+'</p>' msg = Message(subject="testing", sender="*****@*****.**", recipients=["*****@*****.**"], body=text_string, html=html_string) mailer.send_immediately(msg, True)
def send_confirmation_email(email, link): email = email link = link mailer = Mailer(host=host, port=port, username=username, password=password, ssl=True) subject = "Welcome. Please verify your email." body = f'Please verify your email by clicking this link: {link} ' #Create html.jinja2 template for email body message = Message(subject=subject, sender=username, recipients=[email], body=body) mailer.send_immediately(message)
def test_send_immediately_and_fail_silently(self): from pyramid_mailer.mailer import Mailer from pyramid_mailer.message import Message mailer = Mailer(host="localhost", port="28322") msg = Message(subject="testing", sender="*****@*****.**", recipients=["*****@*****.**"], body="test") result = mailer.send_immediately(msg, True) self.assertEqual(result, None)
def submitSignup(request): """ Action on submit page. """ try: User.get(request.POST['login']) except couchdbkit.exceptions.ResourceNotFound: pass else: request.session.flash(u"Username already exist") return HTTPFound(location=request.route_path('signup')) if not request.POST['password'].strip(): request.session.flash(u"You realy need a password") return HTTPFound(location=request.route_path('signup')) if not len(request.POST['password'].strip()) >= 8: request.session.flash(u"Password must have at least 8 characters") return HTTPFound(location=request.route_path('signup')) if request.POST['password'] == request.POST['confirmPassword']: password = bcrypt.hashpw(request.POST['password'].encode('utf-8'), bcrypt.gensalt()) user = User(password=password, name=request.POST['name'], description=request.POST['description'], mail=request.POST['email'], random=random.randint(1,1000000000), checked = False ) user._id = request.POST['login'] user.save() if hasattr(request.POST['avatar'], 'filename'): tmph, originImage = tempfile.mkstemp(dir=settings['tmp'], \ suffix="original") os.close(tmph) tmph, thumbImage = tempfile.mkstemp(dir=settings['tmp'], \ suffix="thumb") os.close(tmph) with open(originImage, 'wb') as tmp: tmp.write(request.POST['avatar'].file.read()) fullSize = Image.open(originImage) fullSize.thumbnail(avatarSize, Image.ANTIALIAS) fullSize.save(thumbImage , "JPEG") with open(thumbImage, 'rb') as thumb: user.put_attachment(thumb, 'avatar') os.remove(originImage) os.remove(thumbImage) confirm_link = request.route_url('checkLogin', userid = user._id, randomid = user.random) mailer = Mailer() message = Message(subject="Your subsription !", sender=settings['mail_from'], recipients=[request.POST['email']], body="Confirm the link\n\n%s" % confirm_link) # TODO add link mailer.send_immediately(message, fail_silently=False) return {'name': request.POST['name']} else: return HTTPFound(location=request.route_path('signup'))