I have successfully set up the SMTP server connection in dtable_web_settings.py for the system emails. Our SMTP server does NOT provide/require authentication, so I left EMAIL_HOST_USER and EMAIL_HOST_PASSWORD empty, which works fine.
However if I want to send email from a table (e.g. via a button) I have to setup a table-specific “third-party account setting”:
Unfortunately I cannot configure an empty user name and password here.
Is there any way to send emails from a table with an SMTP server without authorization?
Hi Simon,
the third account management in the web interface requires username and password.
You can use the ‘Add A 3rd Party Email Account in A Base’ API call to create an email account without usernamen and password.
I just tested it and successfully created this email account in a base …
Thanks for the hint, I tested it. I can create the 3rd party account from curl, however I cannot send test emails. In dtable-events.log I read
[2022-05-12 14:37:42,401] task_message_manager.py[line:70] [INFO] Run task: 1652366262400 <function send_email_msg at 0x7f8272f90d40>
[2022-05-12 14:38:12,420] init.py[line:389] [WARNING] Email sending failed. email: , error: The handshake operation timed out
[2022-05-12 14:38:12,420] task_message_manager.py[line:82] [ERROR] Failed to handle task 1652366262400, error: Server not connected
Is it possible that the reason for this is that our server does not expect a TLS connection? It runs on standard port 25 without TLS, so in dtable_web_settings.py I set
EMAIL_USE_TLS = False
How can I achieve something similar in the API call?
For the moment I build a server-side python script as a workaround to enable sending mails via SMTP withoul TLS and authentication. If anybody is interested:
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.header import Header
from urllib import parse
from datetime import datetime
import requests
from seatable_api import Base, context
base = Base(context.api_token, context.server_url)
base.auth()
# vars
sender = "my.email@domain.de"
subject = 'My ubject line'
# set receivers
receivers = ["receiver1@domain.com","receiver2@domain.com"]
# prepare msg
msg = MIMEMultipart('mixed')
msg['Subject'] = Header(subject, 'utf-8').encode()
msg['From'] = 'TMO seatable <my.email@domain.de>'
msg['To'] = ";".join(receivers)
html = """
<html>
<head></head>
<body>Hallo everybody,<br/><br/>
here comes my mail.<br/><br/>
Greetings,<br/><br/>
Me
</body>
</html>
"""
msg.attach(MIMEText(html,'html', 'utf-8'))
# send mail
server = smtplib.SMTP('mailhost.domain.de', 25)
server.sendmail(sender, receivers, msg.as_string())
server.quit()