2025-06-04 01:34:27 +08:00
import os
import logging
from typing import Optional
import mailtrap as mt
from utils . config import config
logger = logging . getLogger ( __name__ )
class EmailService :
def __init__ ( self ) :
self . api_token = os . getenv ( ' MAILTRAP_API_TOKEN ' )
self . sender_email = os . getenv ( ' MAILTRAP_SENDER_EMAIL ' , ' dom@kortix.ai ' )
self . sender_name = os . getenv ( ' MAILTRAP_SENDER_NAME ' , ' Suna Team ' )
if not self . api_token :
logger . warning ( " MAILTRAP_API_TOKEN not found in environment variables " )
self . client = None
else :
self . client = mt . MailtrapClient ( token = self . api_token )
def send_welcome_email ( self , user_email : str , user_name : Optional [ str ] = None ) - > bool :
if not self . client :
logger . error ( " Cannot send email: MAILTRAP_API_TOKEN not configured " )
return False
if not user_name :
user_name = user_email . split ( ' @ ' ) [ 0 ] . title ( )
subject = " 🎉 Welcome to Suna — Let ' s Get Started "
html_content = self . _get_welcome_email_template ( user_name )
text_content = self . _get_welcome_email_text ( user_name )
return self . _send_email (
to_email = user_email ,
to_name = user_name ,
subject = subject ,
html_content = html_content ,
text_content = text_content
)
def _send_email (
self ,
to_email : str ,
to_name : str ,
subject : str ,
html_content : str ,
text_content : str
) - > bool :
try :
mail = mt . Mail (
sender = mt . Address ( email = self . sender_email , name = self . sender_name ) ,
to = [ mt . Address ( email = to_email , name = to_name ) ] ,
subject = subject ,
text = text_content ,
html = html_content ,
category = " welcome "
)
response = self . client . send ( mail )
logger . info ( f " Welcome email sent to { to_email } . Response: { response } " )
return True
except Exception as e :
logger . error ( f " Error sending email to { to_email } : { str ( e ) } " )
return False
def _get_welcome_email_template ( self , user_name : str ) - > str :
return f """ <!DOCTYPE html>
< html lang = " en " >
< head >
< meta charset = " UTF-8 " >
< meta name = " viewport " content = " width=device-width, initial-scale=1.0 " >
< title > Welcome to Kortix Suna < / title >
< style >
body { {
font - family : Arial , sans - serif ;
background - color : #ffffff;
color : #000000;
margin : 0 ;
padding : 0 ;
line - height : 1.6 ;
} }
. container { {
max - width : 600 px ;
margin : 40 px auto ;
padding : 30 px ;
background - color : #ffffff;
} }
. logo - container { {
text - align : center ;
margin - bottom : 30 px ;
padding : 10 px 0 ;
} }
. logo { {
max - width : 100 % ;
height : auto ;
max - height : 60 px ;
display : inline - block ;
} }
h1 { {
font - size : 24 px ;
color : #000000;
margin - bottom : 20 px ;
} }
p { {
margin - bottom : 16 px ;
} }
a { {
color : #3366cc;
text - decoration : none ;
} }
a : hover { {
text - decoration : underline ;
} }
. button { {
display : inline - block ;
margin - top : 30 px ;
background - color : #3B82F6;
color : white ! important ;
padding : 14 px 24 px ;
text - align : center ;
text - decoration : none ;
font - weight : bold ;
border - radius : 6 px ;
border : none ;
} }
. button : hover { {
background - color : #2563EB;
text - decoration : none ;
} }
. emoji { {
font - size : 20 px ;
} }
< / style >
< / head >
< body >
< div class = " container " >
< div class = " logo-container " >
< img src = " https://i.postimg.cc/WdNtRx5Z/kortix-suna-logo.png " alt = " Kortix Suna Logo " class = " logo " >
< / div >
< h1 > Welcome to Kortix Suna ! < / h1 >
< p > Hi { user_name } , < / p >
< p > < em > < strong > Welcome to Kortix Suna — we ' re excited to have you on board!</strong></em></p>
< p > To get started , we ' d like to get to know you better: fill out this short <a href= " https://docs.google.com/forms/d/e/1FAIpQLSef1EHuqmIh_iQz-kwhjnzSC3Ml-V_5wIySDpMoMU9W_j24JQ/viewform " >form</a>!</p>
2025-07-05 00:49:55 +08:00
< p > To celebrate your arrival , here ' s a <strong>15 % d iscount</strong> for your first month to get more usage:</p>
2025-06-04 01:34:27 +08:00
< p > 🎁 Use code < strong > WELCOME15 < / strong > at checkout . < / p >
< p > Let us know if you need help getting started or have questions — we ' re always here, and join our <a href= " https://discord.com/invite/FjD644cfcs " >Discord community</a>.</p>
2025-06-24 20:44:25 +08:00
< p > < strong > For your business : < / strong > if you want to automate manual and ordinary tasks for your company , book a call with us < a href = " https://cal.com/team/kortix/enterprise-demo " > here < / a > < / p >
2025-06-24 20:27:41 +08:00
2025-06-04 01:34:27 +08:00
< p > Thanks again , and welcome to the Suna community < span class = " emoji " > 🌞 < / span > < / p >
< p > — The Suna Team < / p >
< a href = " https://www.suna.so/ " class = " button " > Go to the platform < / a >
< / div >
< / body >
< / html > """
def _get_welcome_email_text ( self , user_name : str ) - > str :
return f """ Hi { user_name } ,
Welcome to Suna — we ' re excited to have you on board!
To get started , we ' d like to get to know you better: fill out this short form!
https : / / docs . google . com / forms / d / e / 1 FAIpQLSef1EHuqmIh_iQz - kwhjnzSC3Ml - V_5wIySDpMoMU9W_j24JQ / viewform
2025-07-05 00:49:55 +08:00
To celebrate your arrival , here ' s a 15 % d iscount for your first month to get more usage:
2025-06-04 01:34:27 +08:00
🎁 Use code WELCOME15 at checkout .
Let us know if you need help getting started or have questions — we ' re always here, and join our Discord community: https://discord.com/invite/FjD644cfcs
2025-06-24 20:27:41 +08:00
For your business : if you want to automate manual and ordinary tasks for your company , book a call with us here : https : / / cal . com / team / kortix / enterprise - demo
2025-06-04 01:34:27 +08:00
Thanks again , and welcome to the Suna community 🌞
— The Suna Team
Go to the platform : https : / / www . suna . so /
- - -
© 2024 Suna . All rights reserved .
You received this email because you signed up for a Suna account . """
email_service = EmailService ( )