mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
email changes for aws ses
This commit is contained in:
parent
40de319b9a
commit
6f32e8f20d
7 changed files with 18 additions and 20 deletions
|
@ -97,8 +97,8 @@ def create_app(config_class=Config):
|
||||||
secure = ()
|
secure = ()
|
||||||
mail_handler = SMTPHandler(
|
mail_handler = SMTPHandler(
|
||||||
mailhost=(app.config['MAIL_SERVER'], app.config['MAIL_PORT']),
|
mailhost=(app.config['MAIL_SERVER'], app.config['MAIL_PORT']),
|
||||||
fromaddr='rimu@chorebuster.net',
|
fromaddr='errors@rimu.geek.nz',
|
||||||
toaddrs=app.config['ADMINS'], subject='CB Failure',
|
toaddrs=app.config['ADMINS'], subject='PieFed error',
|
||||||
credentials=auth, secure=secure)
|
credentials=auth, secure=secure)
|
||||||
mail_handler.setLevel(logging.ERROR)
|
mail_handler.setLevel(logging.ERROR)
|
||||||
app.logger.addHandler(mail_handler)
|
app.logger.addHandler(mail_handler)
|
||||||
|
|
|
@ -106,7 +106,7 @@ def register():
|
||||||
flash(_('Your username contained special letters so it was changed to %(name)s.', name=form.user_name.data), 'warning')
|
flash(_('Your username contained special letters so it was changed to %(name)s.', name=form.user_name.data), 'warning')
|
||||||
user = User(user_name=form.user_name.data, title=form.user_name.data, email=form.real_email.data,
|
user = User(user_name=form.user_name.data, title=form.user_name.data, email=form.real_email.data,
|
||||||
verification_token=verification_token, instance_id=1, ip_address=ip_address(),
|
verification_token=verification_token, instance_id=1, ip_address=ip_address(),
|
||||||
banned=user_ip_banned() or user_cookie_banned(), email_unread_sent=False, email_messages_sent=False,
|
banned=user_ip_banned() or user_cookie_banned(), email_unread_sent=False,
|
||||||
referrer=session.get('Referer'))
|
referrer=session.get('Referer'))
|
||||||
user.set_password(form.password.data)
|
user.set_password(form.password.data)
|
||||||
db.session.add(user)
|
db.session.add(user)
|
||||||
|
|
|
@ -202,8 +202,8 @@ def register(app):
|
||||||
posts = posts.limit(20).all()
|
posts = posts.limit(20).all()
|
||||||
|
|
||||||
# Send email!
|
# Send email!
|
||||||
send_email(_('You have unread notifications'),
|
send_email(_('[PieFed] You have unread notifications'),
|
||||||
sender='PieFed <rimu@chorebuster.net>',
|
sender=f'PieFed <noreply@{current_app.config["SERVER_NAME"]}>',
|
||||||
recipients=[user.email],
|
recipients=[user.email],
|
||||||
text_body=flask.render_template('email/unread_notifications.txt', user=user,
|
text_body=flask.render_template('email/unread_notifications.txt', user=user,
|
||||||
notifications=notifications),
|
notifications=notifications),
|
||||||
|
|
15
app/email.py
15
app/email.py
|
@ -12,7 +12,7 @@ CHARSET = "UTF-8"
|
||||||
def send_password_reset_email(user):
|
def send_password_reset_email(user):
|
||||||
token = user.get_reset_password_token()
|
token = user.get_reset_password_token()
|
||||||
send_email(_('[PieFed] Reset Your Password'),
|
send_email(_('[PieFed] Reset Your Password'),
|
||||||
sender='PieFed <rimu@chorebuster.net>',
|
sender=f'PieFed <noreply@{current_app.config["SERVER_NAME"]}>',
|
||||||
recipients=[user.email],
|
recipients=[user.email],
|
||||||
text_body=render_template('email/reset_password.txt',
|
text_body=render_template('email/reset_password.txt',
|
||||||
user=user, token=token),
|
user=user, token=token),
|
||||||
|
@ -21,8 +21,8 @@ def send_password_reset_email(user):
|
||||||
|
|
||||||
|
|
||||||
def send_verification_email(user):
|
def send_verification_email(user):
|
||||||
send_email(_('Please verify your email address'),
|
send_email(_('[PieFed] Please verify your email address'),
|
||||||
sender='PieFed <rimu@chorebuster.net>',
|
sender=f'PieFed <noreply@{current_app.config["SERVER_NAME"]}>',
|
||||||
recipients=[user.email],
|
recipients=[user.email],
|
||||||
text_body=render_template('email/verification.txt', user=user),
|
text_body=render_template('email/verification.txt', user=user),
|
||||||
html_body=render_template('email/verification.html', user=user))
|
html_body=render_template('email/verification.html', user=user))
|
||||||
|
@ -31,7 +31,7 @@ def send_verification_email(user):
|
||||||
def send_welcome_email(user, application_required):
|
def send_welcome_email(user, application_required):
|
||||||
subject = _('Your application has been approved - welcome to PieFed') if application_required else _('Welcome to PieFed')
|
subject = _('Your application has been approved - welcome to PieFed') if application_required else _('Welcome to PieFed')
|
||||||
send_email(subject,
|
send_email(subject,
|
||||||
sender='PieFed <rimu@chorebuster.net>',
|
sender=f'PieFed <noreply@{current_app.config["SERVER_NAME"]}>',
|
||||||
recipients=[user.email],
|
recipients=[user.email],
|
||||||
text_body=render_template('email/welcome.txt', user=user, application_required=application_required),
|
text_body=render_template('email/welcome.txt', user=user, application_required=application_required),
|
||||||
html_body=render_template('email/welcome.html', user=user, application_required=application_required))
|
html_body=render_template('email/welcome.html', user=user, application_required=application_required))
|
||||||
|
@ -39,9 +39,12 @@ def send_welcome_email(user, application_required):
|
||||||
|
|
||||||
@celery.task
|
@celery.task
|
||||||
def send_async_email(subject, sender, recipients, text_body, html_body, reply_to):
|
def send_async_email(subject, sender, recipients, text_body, html_body, reply_to):
|
||||||
|
if 'ngrok.app' in sender: # for local development
|
||||||
|
sender = 'PieFed <noreply@piefed.social>'
|
||||||
if type(recipients) == str:
|
if type(recipients) == str:
|
||||||
recipients = [recipients]
|
recipients = [recipients]
|
||||||
with current_app.app_context():
|
with current_app.app_context():
|
||||||
|
return_path = 'bounces@' + current_app.config['SERVER_NAME']
|
||||||
try:
|
try:
|
||||||
# Create a new SES resource and specify a region.
|
# Create a new SES resource and specify a region.
|
||||||
amazon_client = boto3.client('ses', region_name=AWS_REGION)
|
amazon_client = boto3.client('ses', region_name=AWS_REGION)
|
||||||
|
@ -63,7 +66,7 @@ def send_async_email(subject, sender, recipients, text_body, html_body, reply_to
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Source=sender,
|
Source=sender,
|
||||||
ReturnPath='bounces@chorebuster.net')
|
ReturnPath=return_path)
|
||||||
else:
|
else:
|
||||||
response = amazon_client.send_email(
|
response = amazon_client.send_email(
|
||||||
Destination={'ToAddresses': recipients},
|
Destination={'ToAddresses': recipients},
|
||||||
|
@ -81,7 +84,7 @@ def send_async_email(subject, sender, recipients, text_body, html_body, reply_to
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Source=sender,
|
Source=sender,
|
||||||
ReturnPath='bounces@chorebuster.net',
|
ReturnPath=return_path,
|
||||||
ReplyToAddresses=[reply_to])
|
ReplyToAddresses=[reply_to])
|
||||||
# message.attach_alternative("...AMPHTML content...", "text/x-amp-html")
|
# message.attach_alternative("...AMPHTML content...", "text/x-amp-html")
|
||||||
|
|
||||||
|
|
|
@ -289,8 +289,8 @@ def test():
|
||||||
posts = posts.limit(20).all()
|
posts = posts.limit(20).all()
|
||||||
|
|
||||||
# Send email!
|
# Send email!
|
||||||
send_email(_('You have unread notifications'),
|
send_email(_('[PieFed] You have unread notifications'),
|
||||||
sender='PieFed <rimu@chorebuster.net>',
|
sender=f'PieFed <noreply@{current_app.config["SERVER_NAME"]}>',
|
||||||
recipients=[user.email],
|
recipients=[user.email],
|
||||||
text_body=flask.render_template('email/unread_notifications.txt', user=user, notifications=notifications),
|
text_body=flask.render_template('email/unread_notifications.txt', user=user, notifications=notifications),
|
||||||
html_body=flask.render_template('email/unread_notifications.html', user=user,
|
html_body=flask.render_template('email/unread_notifications.html', user=user,
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
<p><a href="https://piefed.social/"><img src="https://piefed.social/static/images/logo2.png" style="max-width: 100%; margin-bottom: 20px;" width="50" height="50" alt="PieFed logo" /></a></p>
|
<p><a href="https://piefed.social/"><img src="https://piefed.social/static/images/logo2.png" style="max-width: 100%; margin-bottom: 20px;" width="50" height="50" alt="PieFed logo" /></a></p>
|
||||||
<p>Hi {{ user.display_name() }},</p>
|
<p>Hi {{ user.display_name() }},</p>
|
||||||
<p>
|
<p><a href="{{ url_for('auth.verify_email', token=user.verification_token, _external=True) }}">Please click this like to verify your email address</a>.</p>
|
||||||
To verify your email address
|
|
||||||
<a href="{{ url_for('auth.verify_email', token=user.verification_token, _external=True) }}">
|
|
||||||
click here
|
|
||||||
</a>.
|
|
||||||
</p>
|
|
||||||
<p>Alternatively, you can paste the following link in your browser's address bar:</p>
|
<p>Alternatively, you can paste the following link in your browser's address bar:</p>
|
||||||
<p>{{ url_for('auth.verify_email', token=user.verification_token, _external=True) }}</p>
|
<p>{{ url_for('auth.verify_email', token=user.verification_token, _external=True) }}</p>
|
||||||
<p>Thanks,</p>
|
<p>Thanks,</p>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
Hello {{ user.display_name() }},
|
Hello {{ user.display_name() }},
|
||||||
|
|
||||||
To verify your email address:
|
To verify your email address, please open this link:
|
||||||
|
|
||||||
{{ url_for('auth.verify_email', token=user.verification_token, _external=True) }}
|
{{ url_for('auth.verify_email', token=user.verification_token, _external=True) }}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue