aonestar
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
sp_send_mail
Parameters
Name
Type
Mode
to_addresses
text[]
IN
subject
text
IN
message
text
IN
from_name
text
IN (DEFAULT NULL)
Definition
try: import smtplib, ssl from email.message import EmailMessage server = 'smtp.gmail.com' port = 587 # For starttls sender = 'no-reply-fromas@newsoft.co.th' password = 'Fr0m@sn0reply' if from_name is None: from_address = f'"Fromas Cloud" <{sender}>' else: from_address = f'"{from_name}" <{sender}>' msg = EmailMessage() msg['From'] = from_address #'"+'Fromas Cloud'+" <'+sender+'>' msg['To'] = ','.join(to_addresses) msg['Subject'] = subject msg.set_content(message) # Create a secure SSL context context = ssl.create_default_context() # Try to log in to server and send email try: smtp = smtplib.SMTP(server, port) smtp.ehlo() # Can be omitted smtp.starttls(context=context) # Secure the connection smtp.ehlo() # Can be omitted smtp.login(sender, password) smtp.send_message(msg, sender, to_addresses) plpy.info('Send mail successful: from '+from_address) except Exception as e: plpy.warning(e) plpy.prepare('select sp_log_warning($1,$2)', ['text','text']).execute(['sp_send_mail',e]) finally: smtp.quit() except Exception as e: plpy.warning(e) plpy.prepare('select sp_log_warning($1,$2)', ['text','text']).execute(['sp_send_mail',e])