Skip to content

MuhammadJamee/email_generator

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sending Email with SendGrid

This Python-based SendGrid workflow allows you to send emails with both body content and attachments. The workflow utilizes the SendGrid API to send emails efficiently and reliably.

Key Features:

  • Simple Command-Line Interface: The workflow uses argparse to accept command-line arguments, making it easy to specify the recipient, subject, body content in markdown format, sender's email address, and the SendGrid API key.

  • Markdown Support: You can compose the body content of the email using markdown syntax, allowing for easy formatting of the email's text.

  • Multiple Recipients: The workflow supports sending emails to multiple recipients simultaneously, making it convenient for reaching multiple recipients with a single command.

  • Attachment Support: You can attach files to the email by providing the file path as an argument, making it possible to send important files along with the email.

To use the workflow, ensure that you have the necessary dependencies installed by checking the requirements.txt file. Make sure to set up your SendGrid API key and replace YOUR_SENDGRID_API_KEY with your actual API key in the command-line arguments.

Example Usage:

python send_email_script.py \
    --to [email protected] \
    --subject "Your Subject" \
    --markdown-body "Hello, **This is a sample email** using *markdown*." \
    --from-email [email protected] \
    --api-key YOUR_SENDGRID_API_KEY
      - name: 'Sending Email with SendGrid'
        uses: MuhammadJamee/email_generator@v1
        with:
          sendgrid-api-key: ${{ secrets.SENDGRID_API_KEY }}
          subject: 'Example Build #${{github.run_number}}'
          from-email: [email protected]
          to-email: [email protected]
          body: 'Example is attached'
          attachment-file-path: 'example.zip' 

Example Usage For Multiple Recipients:

sending-email:
  runs-on: ubuntu-latest
  timeout-minutes: 1
  needs: build
  strategy:
    matrix:
      to-emails:
        - [email protected]
        - [email protected]
        - [email protected]
      
    - name: Compress report folder
      run: zip -r example.zip ./example
            
    - name: 'Sending Email with SendGrid'
      uses: MuhammadJamee/email_generator@v1
      with:
        sendgrid-api-key: ${{ secrets.SENDGRID_API_KEY }}
        subject: 'Example Build #${{github.run_number}}'
        from-email: [email protected]
        to-email: ${{ matrix.to-emails }}
        body: 'Example is attached'
        attachment-file-path: 'example.zip'

Please note that this script requires a compatible environment with the correct Python version and dependencies installed. It is recommended to use a virtual environment to manage dependencies effectively.

Enjoy sending emails effortlessly with SendGrid using this Python workflow! If you encounter any issues or errors, refer to the troubleshooting section or check the compatibility of the script with your system's architecture and operating system. Happy emailing!