Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
imagej-elphel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Elphel
imagej-elphel
Commits
b7db818e
Commit
b7db818e
authored
Feb 09, 2026
by
Andrey Filippov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Switching email script for codex to use hosted server SMTP to resolve
deliverability issues
parent
c8ce4160
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
5 deletions
+32
-5
catalog.json
scripts/catalog.json
+1
-1
email_send.py
scripts/email_send.py
+31
-4
No files found.
scripts/catalog.json
View file @
b7db818e
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
{
{
"name"
:
"email_send.py"
,
"name"
:
"email_send.py"
,
"path"
:
"scripts/email_send.py"
,
"path"
:
"scripts/email_send.py"
,
"purpose"
:
"Send
SMTP email via mail.elphel.com using env vars for credentials
."
"purpose"
:
"Send
email via SSH+sendmail on community.elphel.com by default (set ELPHEL_SEND_MODE=smtp to force SMTP)
."
},
},
{
{
"name"
:
"email_fetch.py"
,
"name"
:
"email_fetch.py"
,
...
...
scripts/email_send.py
View file @
b7db818e
#!/usr/bin/env python3
#!/usr/bin/env python3
import
os
import
os
import
smtplib
import
smtplib
import
subprocess
import
email.utils
import
email.utils
from
email.message
import
EmailMessage
from
email.message
import
EmailMessage
from
pathlib
import
Path
from
pathlib
import
Path
...
@@ -9,6 +10,13 @@ SMTP_HOST = os.environ.get("ELPHEL_SMTP_HOST", "mail.elphel.com")
...
@@ -9,6 +10,13 @@ SMTP_HOST = os.environ.get("ELPHEL_SMTP_HOST", "mail.elphel.com")
SMTP_PORT
=
int
(
os
.
environ
.
get
(
"ELPHEL_SMTP_PORT"
,
"465"
))
SMTP_PORT
=
int
(
os
.
environ
.
get
(
"ELPHEL_SMTP_PORT"
,
"465"
))
SMTP_USER
=
os
.
environ
.
get
(
"ELPHEL_SMTP_USER"
,
"codex@elphel.com"
)
SMTP_USER
=
os
.
environ
.
get
(
"ELPHEL_SMTP_USER"
,
"codex@elphel.com"
)
SMTP_PASS
=
os
.
environ
.
get
(
"ELPHEL_SMTP_PASS"
)
SMTP_PASS
=
os
.
environ
.
get
(
"ELPHEL_SMTP_PASS"
)
# ELPHEL_SEND_MODE=ssh_sendmail (default) or smtp.
# Defaulting to ssh_sendmail avoids sending from the local LAN IP, which can trigger
# recipient-side policy/reputation blocks.
SEND_MODE
=
os
.
environ
.
get
(
"ELPHEL_SEND_MODE"
,
"ssh_sendmail"
)
.
lower
()
SEND_SSH_HOST
=
os
.
environ
.
get
(
"ELPHEL_SEND_SSH_HOST"
,
"community.elphel.com"
)
SEND_SSH_USER
=
os
.
environ
.
get
(
"ELPHEL_SEND_SSH_USER"
,
"elphel5"
)
SEND_SSH_PORT
=
os
.
environ
.
get
(
"ELPHEL_SEND_SSH_PORT"
,
""
)
OUT_DIR
=
os
.
environ
.
get
(
"EMAIL_OUT_DIR"
,
"attic/email_outbox"
)
OUT_DIR
=
os
.
environ
.
get
(
"EMAIL_OUT_DIR"
,
"attic/email_outbox"
)
...
@@ -23,9 +31,27 @@ def _write_index(index_path, values):
...
@@ -23,9 +31,27 @@ def _write_index(index_path, values):
f
.
write
(
line
+
"
\n
"
)
f
.
write
(
line
+
"
\n
"
)
def
send_email
(
subject
,
body
,
to_addrs
,
cc_addrs
=
None
):
def
_send_via_smtp
(
msg
,
recipients
):
if
not
SMTP_PASS
:
if
not
SMTP_PASS
:
raise
SystemExit
(
"Set ELPHEL_SMTP_PASS"
)
raise
SystemExit
(
"Set ELPHEL_SMTP_PASS"
)
with
smtplib
.
SMTP_SSL
(
SMTP_HOST
,
SMTP_PORT
)
as
s
:
s
.
login
(
SMTP_USER
,
SMTP_PASS
)
s
.
send_message
(
msg
,
to_addrs
=
recipients
)
def
_send_via_ssh_sendmail
(
msg
):
ssh_target
=
f
"{SEND_SSH_USER}@{SEND_SSH_HOST}"
ssh_cmd
=
[
"ssh"
]
if
SEND_SSH_PORT
:
ssh_cmd
+=
[
"-p"
,
SEND_SSH_PORT
]
ssh_cmd
+=
[
ssh_target
,
"/usr/sbin/sendmail"
,
"-t"
,
"-f"
,
SMTP_USER
]
try
:
subprocess
.
run
(
ssh_cmd
,
input
=
msg
.
as_bytes
(),
check
=
True
)
except
FileNotFoundError
:
raise
SystemExit
(
"ssh not found; install openssh-client or use SMTP mode"
)
def
send_email
(
subject
,
body
,
to_addrs
,
cc_addrs
=
None
):
msg
=
EmailMessage
()
msg
=
EmailMessage
()
msg
[
"Subject"
]
=
subject
msg
[
"Subject"
]
=
subject
msg
[
"From"
]
=
SMTP_USER
msg
[
"From"
]
=
SMTP_USER
...
@@ -48,9 +74,10 @@ def send_email(subject, body, to_addrs, cc_addrs=None):
...
@@ -48,9 +74,10 @@ def send_email(subject, body, to_addrs, cc_addrs=None):
encoding
=
"utf-8"
,
encoding
=
"utf-8"
,
)
)
_write_index
(
out_dir
/
"index.csv"
,
[
email
.
utils
.
formatdate
(
localtime
=
True
),
SMTP_USER
,
","
.
join
(
to_addrs
),
","
.
join
(
cc_addrs
or
[]),
subject
,
str
(
out_path
)])
_write_index
(
out_dir
/
"index.csv"
,
[
email
.
utils
.
formatdate
(
localtime
=
True
),
SMTP_USER
,
","
.
join
(
to_addrs
),
","
.
join
(
cc_addrs
or
[]),
subject
,
str
(
out_path
)])
with
smtplib
.
SMTP_SSL
(
SMTP_HOST
,
SMTP_PORT
)
as
s
:
if
SEND_MODE
==
"ssh_sendmail"
:
s
.
login
(
SMTP_USER
,
SMTP_PASS
)
_send_via_ssh_sendmail
(
msg
)
s
.
send_message
(
msg
,
to_addrs
=
recipients
)
else
:
_send_via_smtp
(
msg
,
recipients
)
def
main
():
def
main
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment