API for auto-system emails

Hi, I am glad that the installation of the Mail-in-a-box went well. Now I am having a hard time to send out auto system email through roundcube. I tried my own python script like this:

#!/usr/bin/python
import sys
import smtplib
import string

HOST = "box.example.com"
SUBJECT = "(No Subject)"
TO = "error@example.com"
FROM = "default@example.com"
PASSWORD = ""
text = "Wrong sender"
if len(sys.argv) == 6:
	FROM, TO, PASSWORD, SUBJECT, text = sys.argv[1:6]
BODY = string.join((
	"From: %s" % FROM,
	"To: %s" % TO,
	"Subject: %s" % SUBJECT,
	"",
	text
	), "\r\n")
try:
	server = smtplib.SMTP(HOST,"587")
	server.ehlo()
	if server.has_extn('STARTTLS'):
		server.starttls()
		server.ehlo()
	server.login(FROM, PASSWORD)
	server.sendmail(FROM, [TO], BODY)
	server.quit()
	print "sent!"
	exit(1)
except:
	print "did't sent!"
	server.quit()
	exit(0)

However, the email doesn’t work properly when I sent it to gmail. But Roundcube sent to gmail before. I am wondering is there any kind of API for auto system email?

Auto system email? You mean a script to send email from your host? Was your email in GMAIL’s SPAM folder?

Yes, similar to an authentication email when user registered on the server. Do you have any idea how to implement it? The rason why Gmail block my email is because the malformat of my code. I wish the roundcube provides some APIs for me to decorate my email. Thank you.

Roundcube is not the email server, it is just an email client like outlook.

In order to send mail using external scripts, you need:

DO NOT use SSL for SMTP. If you are looking to do mass email, I suggest using https://www.mailgun.com/.

I don’t know python but my google search suggests https://docs.python.org/2/library/email-examples.html is the best place for an example on using the python package “smtplib”

That is what I am looking for. The Mailgun! But I did used the smtplib in python with STARTTLS. Only Gmail will scan SPAM for hours. Finally they let my email through. They said the email header is not what Google expected. I received my email immediately on apple mail.

@raydrrrr What you’re doing in Python is essentially correct. That should work fine. If it’s not, you should compare the raw email headers that you see in Gmail between what you get when you send from Python and what you get when you send from Roundcube and make sure you’re constructing the headers in Python correctly.

1 Like

Yeah, I tried some headers. None of them works fine for me. All the headers are requiring the what email client is used. In my case, I am using a script. I am worrying about being blocked by Gmail, if I keep trying different headers.

BODY = "\n".join((
	"To: %s" % TO,
	"From: %s" % FROM,
	"Subject: %s" % SUBJECT,
	"Date: %s" % str(datetime.now()),
	"Return-Path: %s" % FROM,
	"Envelope-To: %s" % TO,
	"User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:45.0)",
	" Gecko/20100101 Thunderbird/45.8.0",
	"MIME-Version: 1.0",
	"Content-Type: text/plain; charset=utf-8",
	"Content-Transfer-Encoding: 7bit",
	text,
	"\r\n"))

I will try the Mailgun today later.

try this simple…python send email