SMTP without username and password

Hello support,

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”:

image

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?

Thanks a lot,

Simon

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 …

using this call (base id and token exemplary of course):

curl --location --request POST 'https://cloud.seatable.io/api/v2.1/third-party-accounts/0639b2b3-ffe6-459b-a48a-bd4d4aa87020/' \
--header 'Authorization: Token 97e34b23e92692ac17f4b5e346c5a60a9207b66c' \
--header 'Content-Type: application/json' \
--data-raw '{
    "account_name": "NAME_FOR_ACCOUNT",
    "account_type": "email",
    "detail": {
        "email_host":"smtp@example.com", 
        "email_port":587,
        "host_user":"",
        "password":""
    }
}'

I haven’t tested it though, if the account can be used. Could you report your experience?

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?

@daniel.pan Can you comment?

For third party account, username and password is required.

OK, so that would be become a feature request. :slight_smile:

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()

Best,

Simon

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.