'Sending email with Github Actions

I am exploring Github Actions and i want to send email with Github actions. but github is giving me the following error.

Run dawidd6/[email protected]
Error: Invalid login: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbt
534-5.7.14 q937LSp00ryw6TWRxw0-nnKJEijBq83UwreLR6Bu4wr_MwGSeBWNF6rFleIEyw6a9Z0Le
534-5.7.14 b7A1GlsFzIiog5p_U3BAcRhFo5EWeHW25UREP_QJ2oZPf5ZKHynU-D6iScC6bopH>
534-5.7.14 Please log in via your web browser and then try again.
534-5.7.14  Learn more at
534 5.7.14  https://support.google.com/mail/answer/78754 fw21sm11223135pjb.25 - gsmtp

error Image

I am following this article to send email with Github actions.

my .yml code look like this.

name: GitHub Actions Demo
on: [push]
jobs:
  Explore-GitHub-Actions:
    runs-on: ubuntu-latest
    steps:
      - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
      - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
      - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
      - name: Check out repository code
        uses: actions/checkout@v2
      - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
      - run: echo "🖥️ The workflow is now ready to test your code on the runner."
      - name: List files in the repository
        run: |
          ls ${{ github.workspace }}
      - run: echo "🍏 This job's status is ${{ job.status }}."

  sending-email:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository code
        uses: actions/checkout@v2
      - name: Send email
        uses: dawidd6/[email protected]
        with:
          server_address: smtp.gmail.com
          server_port: 465
          username: ${{secrets.GMAIL_USERNAME}}
          password: ${{secrets.GMAIL_PASSWORD}}
          subject: Message from github actions.
          to: [email protected]
          from: deepak deori
          secure: true
          body: workflow for ${{github.repository}} completed successfully!

In my second job i have specified to send email.



Solution 1:[1]

Gmail security settings may cause this Action to fail. This failure sends you this message.

Changes in Gmail settings may be necessary to get this action to work.

  1. Check that IMAP is turned on: https://support.google.com/mail/answer/7126229?hl=en#zippy=%2Cstep-check-that-imap-is-turned-on

  2. Go to your account and enable two-factor authentication: https://myaccount.google.com/security

  3. When you have 2FA set up, you’ll need to create an App Password. This blog explains how you can create it: https://umd.service-now.com/itsupport?id=kb_article&article=KB0015112&sys_kb_id=76433076dbdf8c904cb035623996194b&spa=1

Then you need to update the ${{secrets.GMAIL_PASSWORD}} for this new App Password.

Solution 2:[2]

Once check out this repository, I have set up mailing services in them https://github.com/GitHub-Campus-IITM/support/blob/main/.github/workflows/hiring.yml

on:
  issues:
    types: [labeled]

jobs:
  Broadcast:
    if: ${{ github.event.label.name == 'Hiring' }}
    runs-on: ubuntu-latest
    steps:
      - name: Issue Parser
        uses: stefanbuck/github-issue-parser@v2
        id: issue-parser
        with:
          template-path: .github/ISSUE_TEMPLATE/Opportunity.yml
      - run: | 
          JSON=`echo '${{ steps.issue-parser.outputs.jsonString }}'`
          echo $JSON
          com=`echo $(jq -r '.company' <<< "$JSON")`
          reg=`echo $(jq -r '.registration' <<< "$JSON")`
          jd=`echo $(jq -r '.jd' <<< "$JSON")`
          echo "<h1> Opprtunity from `echo $com` </h1> <div> <h2>Job Description</h2><div>`echo $jd` </div></div><div>Interested students please apply here: `echo $reg`<div>" > temp.html
              
      - name: Send mail
        uses: dawidd6/action-send-mail@v3
        with:
          server_address: smtp.gmail.com
          server_port: 465
          username: ${{SECRETS.EMAIL}}
          password: ${{SECRETS.PASSWORD}}
          subject: Opportunity for you
          to: [email protected]
          cc: [email protected]
          from: GitHub Campus Expert
          html_body: file://temp.html
          secure: true
          ignore_cert: true
          convert_markdown: true
          priority: low
          
      - name: Close Issue
        uses: peter-evans/close-issue@v1
        with:
          comment: |
            Thank you very much for this opportunity.
            We have forwarded it to the students ??.

There are some extra stuff too, but I think this will help you.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jeremy Caney
Solution 2 Sudip Mondal