Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to configure the send mail functionality #670

Closed
arm2arm opened this issue Sep 23, 2022 · 7 comments · Fixed by #713 or reanahub/reana-commons#393
Closed

Unable to configure the send mail functionality #670

arm2arm opened this issue Sep 23, 2022 · 7 comments · Fixed by #713 or reanahub/reana-commons#393
Assignees

Comments

@arm2arm
Copy link

arm2arm commented Sep 23, 2022

According to the documentation https://github.com/reanahub/reana/tree/master/helm/reana we have configured the values.yaml to enable email notifications and validations. Unfortuneatly our internal mailserver is not SSL encrypted. So in order to test the mail functions we moved to DEBUG mode according this line in the https://github.com/reanahub/reana-commons/blob/1b9aa72a7090870f60335e75e592e6f3737debc2/reana_commons/email.py#L48 we have tryed to avoid SSL and password for the mail server, so we have added in values.yaml following:

# REANA components configuration
components:
  reana_server:
    environment:
      REANA_EMAIL_SMTP_SERVER: "XXX.XXX.XX.XXX"
      REANA_EMAIL_SMTP_PORT: 25
      REANA_EMAIL_SENDER: "test@aip.de" 
      REANA_EMAIL_RECEIVER: "noreply@aip.de"
      REANA_EMAIL_LOGIN: ""
      REANA_EMAIL_PASSWORD: ""

      FLASK_ENV: "development"

Looks like our mail server getting requests but email is rejected by following error:

postfix/smtp[21505]: XXXXXXX: to=<XXXX@XXXX>, relay=127.0.0.1[127.0.0.1]:10024, delay=0.07, delays=0.01/0.01/0/0.06, dsn=2.6.0, status=sent (250 2.6.0 Ok, discarded, id=14729-02 - BAD HEADER)

Any idea how to fix this?
Would be great that REANA can use directly mail server without SSL if no password is set and the mailserver port is 25

thank you beforehand,
Arman.

@tiborsimko
Copy link
Member

Hi @arm2arm, the best would be to amend reana-commons source code so that TLS would be optional.

If your mail server does not necessitate any TLS or any login, would it be sufficient to comment out the server.starttls() and the server.login() calls in the reana-commons/email.py main business logic part below?

    with smtplib.SMTP(REANA_EMAIL_SMTP_SERVER, REANA_EMAIL_SMTP_PORT) as server:
        if os.getenv("FLASK_ENV") != "development":
            server.starttls(context=context)
            server.login(login_email, REANA_EMAIL_PASSWORD)
        server.send_message(message)
        logging.info(
            "Email sent, login: {}, sender: {}, receiver: {}".format(
                login_email, sender_email, receiver_email
            )
        )
        logging.info("Body:\n{}".format(message))

For example, you can make a test such as connecting into the running container:

$ kubectl exec -i -t deployment/reana-server -c rest-api -- ipython

and, in the iPython shell, try to send email following the same commands but without these two lines.

Would it work? Or would your email server necessitate some other options to be set?

Once we find out, we'll be able to make a new release of reana-commons where the TLS would be optional and governed by some Helm values.

@arm2arm
Copy link
Author

arm2arm commented Sep 28, 2022

I have setup a TLS mailserver connection.
Now the email server works but not with reana. I have tested on the machines now with the python script:

cat send_email.py 
import smtplib, ssl
from email.mime.text import MIMEText

# Email configuration
REANA_EMAIL_SMTP_SERVER = "xxxx" 
REANA_EMAIL_SMTP_PORT = 465
REANA_EMAIL_LOGIN =  "reana-service"
REANA_EMAIL_SENDER = "reana-service@xxx"
REANA_EMAIL_PASSWORD = "xxxx"

sender = REANA_EMAIL_SENDER
receivers = ['xxxx']

port = REANA_EMAIL_SMTP_PORT
user = REANA_EMAIL_LOGIN
password = REANA_EMAIL_PASSWORD

msg = MIMEText('This is test mail')

msg['Subject'] = 'Test mail'
msg['From'] = 'reana-service@xxx'
msg['To'] = 'xxxx'

context = ssl.create_default_context()

with smtplib.SMTP_SSL(REANA_EMAIL_SMTP_SERVER, port, context=context) as server:

    server.login(user, password)
    server.sendmail(sender, receivers, msg.as_string())
    print('mail successfully sent')

It works inside the container without problems.
Also I checked in the environment variables, they are ok REANA_EMAIL*

reana gives strange error after long waiting:

root@reana:~# kubectl exec -i -t deployment/reana-server -- flask reana-admin token-grant --email  XXXXX  --admin-access-token $REANA_ACCESS_TOKEN
Defaulted container "rest-api" out of: rest-api, scheduler
User XXX (XXX) access token status is revoked, do you want to proceed? [y/N]: y
Token for user XXX (XXXX) granted.

Token: XXXX
Something went wrong while granting token:
(-1, b'\x02\x02')

Any hints how to solve this?

thank you beforehand

@mdonadoni
Copy link
Member

Hi @arm2arm, the handling of emails was improved recently (see reanahub/reana-commons@1b9aa72). Would it be possible to try this new version out to check if the issue persists?

These changes are not present in any release yet, so one possibility would be to deploy REANA from master. Otherwise, we can build some custom docker images that include these improvements for the specific version of REANA you have deployed. One other possibility would be to run the code that sends emails manually from inside the cluster, for example by using ipython, as @tiborsimko proposed in his previous reply.

Once we identify the issue, we can proceed with making it possible to disable TLS with a Helm value, if it is still needed.

@arm2arm
Copy link
Author

arm2arm commented Oct 4, 2022

Dear @mdonadoni, sure I can try them on our environment, could you please provide some instructions how to deploy the dev version? currently I am using steps with KIND described here: https://docs.reana.io/administration/deployment/deploying-locally/

@mdonadoni
Copy link
Member

If you only want to deploy the dev version locally to test things out, you can follow the steps in the developers wiki. However, please keep in mind that by following this guide you will set up a full development environment, which might require quite some time.

We are currently in the middle of releasing a new alpha version (0.9.0-alpha.6, see #672), so you can also consider waiting for it to be ready, given that it will be much easier to deploy. Would this work for you?

@mdonadoni
Copy link
Member

We have released version 0.9.0-alpha.6 of REANA, which you can now easily deploy. You can follow the same guide Deploying locally, with just a few changes. In particular, you should fetch these files instead of the ones present in the documentation page:

You will also need to add --version 0.9.0-alpha.6 to the helm install ... command.

@mdonadoni
Copy link
Member

mdonadoni commented May 16, 2023

The issues seem to be related to how REANA connects to SMTP servers.

This is currently how REANA sends emails (src):

    with smtplib.SMTP(REANA_EMAIL_SMTP_SERVER, REANA_EMAIL_SMTP_PORT) as server:
        if os.getenv("FLASK_ENV") != "development":
            server.starttls(context=context)
            server.login(login_email, REANA_EMAIL_PASSWORD)
        server.send_message(message)

A plain-text connection to the SMTP server is opened, after which a STARTTLS command is issued to upgrade to an encrypted connection. However, in this case it's necessary to connect to the server directly with SSL.

Things to do:

  • add possibility to choose SMTP-over-SSL instead of SMTP + STARTTLS (see smptlib.SMTP_SSL)
  • add support for plaint-text SMTP without any kind of encryption (e.g. what is being used for the development email server)
  • make login optional
  • update the docs

@mdonadoni mdonadoni self-assigned this May 22, 2023
mdonadoni added a commit to mdonadoni/reana that referenced this issue May 30, 2023
mdonadoni added a commit to mdonadoni/reana that referenced this issue May 30, 2023
mdonadoni added a commit to mdonadoni/reana-commons that referenced this issue May 30, 2023
mdonadoni added a commit to mdonadoni/reana that referenced this issue Jun 1, 2023
mdonadoni added a commit to mdonadoni/reana that referenced this issue Jun 1, 2023
mdonadoni added a commit to mdonadoni/reana that referenced this issue Mar 5, 2024
chore(reana-ui/master): release 0.9.4

build(reana-ui/package): update yarn.lock (reanahub#399)

build(reana-ui/package): require jsroot<7.6.0 (reanahub#399)

ci(reana-ui/commitlint): allow release commit style (reanahub#400)

docs(reana-ui/authors): complete list of contributors (reanahub#396)

ci(reana-ui/shellcheck): exclude node_modules from the analyzed paths (reanahub#387)

fix(reana-ui/progress): update failed workflows duration using finish time (reanahub#387)

feat(reana-ui/footer): link privacy notice to configured URL (reanahub#393)

refactor(reana-ui/docs): move from reST to Markdown (reanahub#391)

ci(reana-ui/commitlint): check for the presence of concrete PR number (reanahub#390)

ci(reana-ui/shellcheck): fix exit code propagation (reanahub#390)

fix(reana-ui/launcher): remove dollar sign in generated Markdown (reanahub#389)

ci(reana-ui/release-please): update version in package.json and Dockerfile (reanahub#385)

ci(reana-ui/release-please): switch to `simple` release strategy (reanahub#383)

fix(reana-ui/router): show 404 page for invalid URLs (reanahub#382)

ci(reana-ui/release-please): initial configuration (reanahub#380)

ci(reana-ui/commitlint): addition of commit message linter (reanahub#380)

chore(reana-message-broker/master): release 0.9.3

ci(reana-message-broker/commitlint): allow release commit style (reanahub#67)

docs(reana-message-broker/authors): complete list of contributors (reanahub#66)

refactor(reana-message-broker/docs): move from reST to Markdown (reanahub#65)

ci(reana-message-broker/commitlint): check for the presence of concrete PR number (reanahub#64)

ci(reana-message-broker/shellcheck): fix exit code propagation (reanahub#64)

ci(reana-message-broker/release-please): update version in Dockerfile (reanahub#63)

fix(reana-message-broker/startup): handle signals for graceful shutdown (reanahub#59)

ci(reana-message-broker/release-please): initial configuration (reanahub#60)

ci(reana-message-broker/commitlint): addition of commit message linter (reanahub#60)

chore(reana-server/master): release 0.9.3

build(reana-server/python): bump all required packages as of 2024-03-04 (reanahub#674)

build(reana-server/python): bump shared REANA packages as of 2024-03-04 (reanahub#674)

build(reana-server/python): bump shared modules (reanahub#676)

ci(reana-server/commitlint): allow release commit style (reanahub#675)

docs(reana-server/authors): complete list of contributors (reanahub#673)

ci(reana-server/pytest): move to PostgreSQL 14.10 (reanahub#672)

refactor(reana-server/docs): move from reST to Markdown (reanahub#671)

style(reana-server/black): format with black v24 (reanahub#670)

ci(reana-server/commitlint): check for the presence of concrete PR number (reanahub#669)

ci(reana-server/shellcheck): fix exit code propagation (reanahub#669)

ci(reana-server/release-please): update version in Dockerfile/OpenAPI specs (reanahub#668)

build(reana-server/docker): non-editable submodules in "latest" mode (reanahub#656)

build(reana-server/deps): pin invenio-userprofiles to 1.2.4 (reanahub#665)

ci(reana-server/release-please): initial configuration (reanahub#665)

ci(reana-server/commitlint): addition of commit message linter (reanahub#665)

chore(reana-workflow-controller/master): release 0.9.3

build(reana-workflow-controller/python): bump all required packages as of 2024-03-04 (reanahub#574)

build(reana-workflow-controller/python): bump shared REANA packages as of 2024-03-04 (reanahub#574)

feat(reana-workflow-controller/manager): increase termination period of run-batch pods (reanahub#572)

ci(reana-workflow-controller/commitlint): allow release commit style (reanahub#575)

feat(reana-workflow-controller/manager): pass custom env variables to job controller (reanahub#571)

feat(reana-workflow-controller/manager): pass custom env variables to workflow engines (reanahub#571)

docs(reana-workflow-controller/authors): complete list of contributors (reanahub#570)

ci(reana-workflow-controller/pytest): move to PostgreSQL 14.10 (reanahub#568)

fix(reana-workflow-controller/manager): use valid group name when calling `groupadd` (reanahub#566)

refactor(reana-workflow-controller/docs): move from reST to Markdown (reanahub#567)

fix(reana-workflow-controller/stop): store engine logs of stopped workflow (reanahub#563)

fix(reana-workflow-controller/manager): graceful shutdown of job-controller (reanahub#559)

feat(reana-workflow-controller/manager): call shutdown endpoint before workflow stop (reanahub#559)

refactor(reana-workflow-controller/consumer): do not update status of jobs (reanahub#559)

style(reana-workflow-controller/black): format with black v24 (reanahub#564)

ci(reana-workflow-controller/commitlint): check for the presence of concrete PR number (reanahub#562)

ci(reana-workflow-controller/shellcheck): fix exit code propagation (reanahub#562)

ci(reana-workflow-controller/release-please): update version in Dockerfile/OpenAPI specs (reanahub#558)

build(reana-workflow-controller/docker): non-editable submodules in "latest" mode (reanahub#551)

ci(reana-workflow-controller/release-please): initial configuration (reanahub#555)

ci(reana-workflow-controller/commitlint): addition of commit message linter (reanahub#555)

chore(reana-job-controller/master): release 0.9.3

build(reana-job-controller/python): bump all required packages as of 2024-03-04 (reanahub#442)

build(reana-job-controller/python): bump shared REANA packages as of 2024-03-04 (reanahub#442)

ci(reana-job-controller/commitlint): allow release commit style (reanahub#443)

build(reana-job-controller/certificates): update expired CERN Grid CA certificate (reanahub#440)

fix(reana-job-controller/database): limit the number of open database connections (reanahub#437)

docs(reana-job-controller/authors): complete list of contributors (reanahub#434)

perf(reana-job-controller/cache): avoid caching jobs when the cache is disabled (reanahub#435)

ci(reana-job-controller/pytest): move to PostgreSQL 14.10 (reanahub#429)

refactor(reana-job-controller/docs): move from reST to Markdown (reanahub#428)

ci(reana-job-controller/commitlint): check for the presence of concrete PR number (reanahub#425)

ci(reana-job-controller/shellcheck): fix exit code propagation (reanahub#425)

feat(reana-job-controller/shutdown): stop all running jobs before stopping workflow (reanahub#423)

refactor(reana-job-controller/monitor): move fetching of logs to job-manager (reanahub#423)

refactor(reana-job-controller/db): set job status also in the main database (reanahub#423)

refactor(reana-job-controller/monitor): centralise logs and status updates (reanahub#423)

style(reana-job-controller/black): format with black v24 (reanahub#426)

ci(reana-job-controller/release-please): update version in Dockerfile/OpenAPI specs (reanahub#421)

build(reana-job-controller/docker): non-editable submodules in "latest" mode (reanahub#416)

ci(reana-job-controller/release-please): initial configuration (reanahub#417)

ci(reana-job-controller/commitlint): addition of commit message linter (reanahub#417)

chore(reana-workflow-engine-cwl/master): release 0.9.3

build(reana-workflow-engine-cwl/python): bump all required packages as of 2024-03-04 (reanahub#267)

build(reana-workflow-engine-cwl/python): bump shared REANA packages as of 2024-03-04 (reanahub#267)

docs(reana-workflow-engine-cwl/conformance-tests): update CWL conformance test badges (reanahub#264)

ci(reana-workflow-engine-cwl/commitlint): allow release commit style (reanahub#268)

docs(reana-workflow-engine-cwl/authors): complete list of contributors (reanahub#266)

refactor(reana-workflow-engine-cwl/docs): move from reST to Markdown (reanahub#263)

fix(reana-workflow-engine-cwl/progress): handle stopped jobs (reanahub#260)

ci(reana-workflow-engine-cwl/commitlint): check for the presence of concrete PR number (reanahub#262)

ci(reana-workflow-engine-cwl/shellcheck): fix exit code propagation (reanahub#262)

build(reana-workflow-engine-cwl/docker): install correct extras of reana-commons submodule (reanahub#261)

ci(reana-workflow-engine-cwl/release-please): update version in Dockerfile (reanahub#259)

build(reana-workflow-engine-cwl/docker): non-editable submodules in "latest" mode (reanahub#255)

ci(reana-workflow-engine-cwl/release-please): initial configuration (reanahub#256)

ci(reana-workflow-engine-cwl/commitlint): addition of commit message linter (reanahub#256)

chore(reana-workflow-engine-serial/master): release 0.9.3

build(reana-workflow-engine-serial/python): bump all required packages as of 2024-03-04 (reanahub#200)

build(reana-workflow-engine-serial/python): bump shared REANA packages as of 2024-03-04 (reanahub#200)

ci(reana-workflow-engine-serial/commitlint): allow release commit style (reanahub#201)

docs(reana-workflow-engine-serial/authors): complete list of contributors (reanahub#199)

refactor(reana-workflow-engine-serial/docs): move from reST to Markdown (reanahub#198)

fix(reana-workflow-engine-serial/progress): handle stopped jobs (reanahub#195)

ci(reana-workflow-engine-serial/commitlint): check for the presence of concrete PR number (reanahub#197)

ci(reana-workflow-engine-serial/shellcheck): fix exit code propagation (reanahub#197)

build(reana-workflow-engine-serial/docker): install correct extras of reana-commons submodule (reanahub#196)

ci(reana-workflow-engine-serial/release-please): update version in Dockerfile (reanahub#194)

build(reana-workflow-engine-serial/docker): non-editable submodules in "latest" mode (reanahub#190)

ci(reana-workflow-engine-serial/release-please): initial configuration (reanahub#191)

ci(reana-workflow-engine-serial/commitlint): addition of commit message linter (reanahub#191)

chore(reana-workflow-engine-yadage/master): release 0.9.4

build(reana-workflow-engine-yadage/python): bump all required packages as of 2024-03-04 (reanahub#261)

build(reana-workflow-engine-yadage/python): bump shared REANA packages as of 2024-03-04 (reanahub#261)

ci(reana-workflow-engine-yadage/commitlint): allow release commit style (reanahub#262)

docs(reana-workflow-engine-yadage/authors): complete list of contributors (reanahub#260)

refactor(reana-workflow-engine-yadage/docs): move from reST to Markdown (reanahub#259)

fix(reana-workflow-engine-yadage/progress): correctly handle running and stopped jobs (reanahub#258)

ci(reana-workflow-engine-yadage/commitlint): check for the presence of concrete PR number (reanahub#257)

ci(reana-workflow-engine-yadage/shellcheck): fix exit code propagation (reanahub#257)

build(reana-workflow-engine-yadage/docker): install correct extras of reana-commons submodule (reanahub#256)

ci(reana-workflow-engine-yadage/release-please): update version in Dockerfile (reanahub#254)

build(reana-workflow-engine-yadage/docker): non-editable submodules in "latest" mode (reanahub#249)

ci(reana-workflow-engine-yadage/release-please): initial configuration (reanahub#251)

ci(reana-workflow-engine-yadage/commitlint): addition of commit message linter (reanahub#251)

chore(reana-workflow-engine-snakemake/master): release 0.9.3

build(reana-workflow-engine-snakemake/python): bump all required packages as of 2024-03-04 (reanahub#85)

build(reana-workflow-engine-snakemake/python): bump shared REANA packages as of 2024-03-04 (reanahub#85)

ci(reana-workflow-engine-snakemake/commitlint): allow release commit style (reanahub#86)

feat(reana-workflow-engine-snakemake/config): get max number of parallel jobs from env vars (reanahub#84)

feat(reana-workflow-engine-snakemake/executor): upgrade to Snakemake v7.32.4 (reanahub#81)

docs(reana-workflow-engine-snakemake/authors): complete list of contributors (reanahub#83)

refactor(reana-workflow-engine-snakemake/docs): move from reST to Markdown (reanahub#82)

fix(reana-workflow-engine-snakemake/progress): handle stopped jobs (reanahub#78)

ci(reana-workflow-engine-snakemake/commitlint): check for the presence of concrete PR number (reanahub#80)

ci(reana-workflow-engine-snakemake/shellcheck): fix exit code propagation (reanahub#80)

build(reana-workflow-engine-snakemake/docker): install correct extras of reana-commons submodule (reanahub#79)

ci(reana-workflow-engine-snakemake/release-please): update version in Dockerfile (reanahub#77)

build(reana-workflow-engine-snakemake/docker): non-editable submodules in "latest" mode (reanahub#73)

ci(reana-workflow-engine-snakemake/release-please): initial configuration (reanahub#74)

ci(reana-workflow-engine-snakemake/commitlint): addition of commit message linter (reanahub#74)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants