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"""

Join {sender.username}'s Business Campaign

{message}

Campaign: {campaign.title}

Target: ${campaign.target_amount}

Support this campaign """ 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