Page MenuHomePhabricator

heirloom-mailx fails trying to send out email from SWAP notebook
Closed, DeclinedPublic

Description

I tried using mailx to send out an email from within a notebook and from within a terminal: echo foo | mailx -s "test" ..@wikimedia.org

This results in a failed to open configuration file /etc/exim4/exim4.conf: Permission denied error.

This would be useful to send out a notification once a long-running query has completed.

Update September 2018: This is still not solved, but I noticed that it works when SSHing directly into notebook1003 (and using heirloom-mailx instead of mailx; IIRC mailx is no longer installed by default in newer Debian versions):

$ echo foo | heirloom-mailx -s "test" ...@wikimedia.org

However it still fails when trying inside a SWAP notebook:

In [11]:  ! echo foo | heirloom-mailx -s "test" ...@wikimedia.org
​
2018-09-22 02:51:51 failed to open configuration file /etc/exim4/exim4.conf: Permission denied (euid=3029 egid=500)
2018-09-22 02:51:51 failed to open configuration file /etc/exim4/exim4.conf: Permission denied (euid=3029 egid=500)
2018-09-22 02:51:51 failed to open configuration file /etc/exim4/exim4.conf: Permission denied (euid=3029 egid=500

Related Objects

Event Timeline

Tbayer added a subscriber: bd808.

From @bd808 on IRC: "I would guess that there is no outbound MX route or that its trying to talk to a gateway that is blackholeing the traffic"

Tbayer renamed this task from mailx gets stuck trying to send out email from SWAP to mailx fails trying to send out email from SWAP.Jun 16 2017, 10:47 PM
Tbayer updated the task description. (Show Details)

From @bd808 on IRC: "I would guess that there is no outbound MX route or that its trying to talk to a gateway that is blackholeing the traffic"

This was based on the original "it just hangs" report and me not thinking at first about how mailx works on the command line. The new description makes the root cause much more obvious.

Added Analytics , as the AE team has taken ownership of SWAP since last year.
@Ottomata , any thoughts? @Neil_P._Quinn_WMF and I wonder if it has to do with the virtual environment.

Tbayer renamed this task from mailx fails trying to send out email from SWAP to heirloom-mailx fails trying to send out email from SWAP notebook.Sep 22 2018, 2:56 AM

So, I just tried to reproduce this, and can't. (notebook1004 was missing a package that caused a different error, but I'm fixing that now. notebook1003 works). I ran this command as tbayer too, and was able to send an email. Are you sure this is still happening?

Ah, sorry, I responded to hastily. The problem is from inside a Jupyter notebook. I'm a bit stumped at the moment, as I can't see why this would work on the shell but not in a Notebook terminal. It likely has something to do with the systemd Jupyter notebook isolation, but still it is strange. Will continue investigating...

Milimetric triaged this task as High priority.
Milimetric moved this task from Incoming to Operational Excellence on the Analytics board.
Milimetric added a project: Analytics-Kanban.

Ah, sorry, I responded to hastily. The problem is from inside a Jupyter notebook. I'm a bit stumped at the moment, as I can't see why this would work on the shell but not in a Notebook terminal. It likely has something to do with the systemd Jupyter notebook isolation, but still it is strange. Will continue investigating...

Thanks @Ottomata! Appreciate anything you might find - or thoughts on alternative ways of sending out such a notification once the notebook has completed a query or calculation.
(CCing @Groceryheist who will have use for this too.)

What type of notebook are you using? Python?

What type of notebook are you using? Python?

Yes - but as mentioned, the same error happens when I try the command in a terminal opened within Jupyter.

Yeah, still don't understand why that doesn't work. In the meantime, you could try sending using Python, this works for me in a Python notebook:

def send_email(from_email, to_email, subject, message):
    import smtplib
    smtp = smtplib.SMTP("localhost")
    message = """From: <{}>
To: <{}>
Subject: SMTP e-mail test

This is a test e-mail message.
""".format(from_email, to_email)
    smtp.sendmail(from_email, [to_email], message)

send_email('otto@wikimedia.org', 'otto@wikimedia.org', 'TEST EMAIL', 'hi there')

Cool! This works great for me. I tweaked it a bit to make the from_email and to_email parameters optional, autogenerating them based on the server name and user name.

In[1]:
# cf. https://phabricator.wikimedia.org/T168103#4635031 :
notebookservername = !hostname
notebookserverdomain =  notebookservername[0]+'.eqiad.wmnet'
username = !whoami

def send_email(subject, body, to_email = username[0]+'@wikimedia.org', from_email = username[0]+'@'+notebookserverdomain):
    import smtplib
    smtp = smtplib.SMTP("localhost")
    message = """From: <{}>
To: <{}>
Subject: {}

{}
""".format(from_email, to_email, subject, body)
    smtp.sendmail(from_email, [to_email], message)

# example uses: 
# send_email('SWAP notebook ready (n/t)', '')
# send_email('SWAP email test', 'test body', 'yourname@wikimedia.org', 'yourname@wikimedia.org')

PS: This solves my own use case and I think that of some other Python users too. Personally I wouldn't mind closing this task, although the problem as stated hasn't been solved yet, and users of other languages might not yet have a way to circumvent it.

Great! Yeah let's leave this open. The real problem is not solved.

mforns lowered the priority of this task from High to Low.Mar 7 2019, 5:51 PM

Not going to work on this unless someone else complains :)