Email Source

Introduction #

SmartChart supports SMTP-based email sending as a data source. Send HTML or plain text emails through configured SMTP servers, useful for scheduled report delivery and alert notifications.

Use Cases #

  • Scheduled report auto-sending
  • Exception alert email notifications
  • Data submission result notifications

Configuration #

Driver: smtp
Connection address: smtp server address (e.g., smtp.qq.com)
Port: 465 (SSL) or 587 (TLS)
Username: email account
Password: email password or authorization code

Usage #

Write email content in the dataset editor:

def dataset(*args, **kwargs):
    sqlList = args[0]
    config = args[1]
    
    import smtplib
    from email.mime.text import MIMEText
    from email.mime.multipart import MIMEMultipart
    
    subject = sqlList[0] if len(sqlList) > 0 else "SmartChart Notification"
    body = sqlList[1] if len(sqlList) > 1 else ""
    to_addr = sqlList[2] if len(sqlList) > 2 else config['user']
    
    msg = MIMEMultipart()
    msg['Subject'] = subject
    msg['From'] = config['user']
    msg['To'] = to_addr
    msg.attach(MIMEText(body, 'html'))
    
    smtp = smtplib.SMTP_SSL(config['host'], int(config.get('port', 465)))
    smtp.login(config['user'], config['password'])
    smtp.sendmail(config['user'], to_addr, msg.as_string())
    smtp.quit()
    
    return {'status': 200, 'msg': 'Email sent successfully'}

Most email providers require an authorization code instead of the account password. Check your provider’s documentation for SMTP settings.