-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail.py
More file actions
28 lines (24 loc) · 842 Bytes
/
email.py
File metadata and controls
28 lines (24 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
def send_invitation_email(to_email, sender, campaign, message):
sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
html_content = f"""
<h2>Join {sender.username}'s Business Campaign</h2>
<p>{message}</p>
<p>Campaign: {campaign.title}</p>
<p>Target: ${campaign.target_amount}</p>
<a href="{campaign.invite_link}">Support this campaign</a>
"""
message = Mail(
from_email='noreply@startup-crowdfund.com',
to_emails=to_email,
subject=f'{sender.username} invited you to support their business',
html_content=html_content
)
try:
sg.send(message)
return True
except Exception as e:
print(f"SendGrid error: {e}")
return False