community.general.sendgrid (1.3.14) — module

Sends an email with the SendGrid API

Authors: Matt Makai (@makaimc)

Install collection

Install with ansible-galaxy collection install community.general:==1.3.14


Add to requirements.yml

  collections:
    - name: community.general
      version: 1.3.14

Description

Sends an email with a SendGrid account through their API, not through the SMTP service.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Send an email to a single recipient that the deployment was successful
  community.general.sendgrid:
    username: "{{ sendgrid_username }}"
    password: "{{ sendgrid_password }}"
    from_address: "ansible@mycompany.com"
    to_addresses:
      - "ops@mycompany.com"
    subject: "Deployment success."
    body: "The most recent Ansible deployment was successful."
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Send an email to more than one recipient that the build failed
  community.general.sendgrid:
      username: "{{ sendgrid_username }}"
      password: "{{ sendgrid_password }}"
      from_address: "build@mycompany.com"
      to_addresses:
        - "ops@mycompany.com"
        - "devteam@mycompany.com"
      subject: "Build failure!."
      body: "Unable to pull source repository from Git server."
  delegate_to: localhost

Inputs

    
cc:
    description:
    - A list of email addresses to cc.
    elements: str
    type: list

bcc:
    description:
    - A list of email addresses to bcc.
    elements: str
    type: list

body:
    description:
    - The e-mail body content.
    required: true
    type: str

api_key:
    description:
    - Sendgrid API key to use instead of username/password.
    type: str

headers:
    description:
    - A dict to pass on as headers.
    type: dict

subject:
    description:
    - The desired subject for the email.
    required: true
    type: str

password:
    description:
    - Password that corresponds to the username.
    - Since 2.2 it is only required if I(api_key) is not supplied.
    type: str

username:
    description:
    - Username for logging into the SendGrid account.
    - Since 2.2 it is only required if I(api_key) is not supplied.
    type: str

from_name:
    description:
    - The name you want to appear in the from field, i.e 'John Doe'.
    type: str

html_body:
    default: 'no'
    description:
    - Whether the body is html content that should be rendered.
    type: bool

attachments:
    description:
    - A list of relative or explicit paths of files you want to attach (7MB limit as per
      SendGrid docs).
    elements: path
    type: list

from_address:
    description:
    - The address in the "from" field for the email.
    required: true
    type: str

to_addresses:
    description:
    - A list with one or more recipient email addresses.
    elements: str
    required: true
    type: list