mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
sendgrid: Update docs (#1557)
* Updated docs * Warn user about required Sendgrid Python library version i.e <=1.6.22 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
eb2cb56a55
commit
818cafc580
2 changed files with 27 additions and 20 deletions
2
changelogs/fragments/1553_sendgrid.yml
Normal file
2
changelogs/fragments/1553_sendgrid.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- sendgrid - update documentation and warn user about sendgrid Python library version (https://github.com/ansible-collections/community.general/issues/1553).
|
|
@ -1,14 +1,14 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# (c) 2015, Matt Makai <matthew.makai@gmail.com>
|
# Copyright: (c) 2015, Matt Makai <matthew.makai@gmail.com>
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = r'''
|
||||||
---
|
---
|
||||||
module: sendgrid
|
module: sendgrid
|
||||||
short_description: Sends an email with the SendGrid API
|
short_description: Sends an email with the SendGrid API
|
||||||
|
@ -23,73 +23,73 @@ notes:
|
||||||
account."
|
account."
|
||||||
- "In order to use api_key, cc, bcc, attachments, from_name, html_body, headers
|
- "In order to use api_key, cc, bcc, attachments, from_name, html_body, headers
|
||||||
you must pip install sendgrid"
|
you must pip install sendgrid"
|
||||||
- "since 2.2 username and password are not required if you supply an api_key"
|
- "since 2.2 I(username) and I(password) are not required if you supply an I(api_key)"
|
||||||
requirements:
|
requirements:
|
||||||
- sendgrid python library
|
- sendgrid Python library 1.6.22 or lower (Sendgrid API V2 supported)
|
||||||
options:
|
options:
|
||||||
username:
|
username:
|
||||||
type: str
|
type: str
|
||||||
description:
|
description:
|
||||||
- username for logging into the SendGrid account.
|
- Username for logging into the SendGrid account.
|
||||||
- Since 2.2 it is only required if api_key is not supplied.
|
- Since 2.2 it is only required if I(api_key) is not supplied.
|
||||||
password:
|
password:
|
||||||
type: str
|
type: str
|
||||||
description:
|
description:
|
||||||
- password that corresponds to the username
|
- Password that corresponds to the username.
|
||||||
- Since 2.2 it is only required if api_key is not supplied.
|
- Since 2.2 it is only required if I(api_key) is not supplied.
|
||||||
from_address:
|
from_address:
|
||||||
type: str
|
type: str
|
||||||
description:
|
description:
|
||||||
- the address in the "from" field for the email
|
- The address in the "from" field for the email.
|
||||||
required: true
|
required: true
|
||||||
to_addresses:
|
to_addresses:
|
||||||
type: list
|
type: list
|
||||||
description:
|
description:
|
||||||
- a list with one or more recipient email addresses
|
- A list with one or more recipient email addresses.
|
||||||
required: true
|
required: true
|
||||||
subject:
|
subject:
|
||||||
type: str
|
type: str
|
||||||
description:
|
description:
|
||||||
- the desired subject for the email
|
- The desired subject for the email.
|
||||||
required: true
|
required: true
|
||||||
api_key:
|
api_key:
|
||||||
type: str
|
type: str
|
||||||
description:
|
description:
|
||||||
- sendgrid API key to use instead of username/password
|
- Sendgrid API key to use instead of username/password.
|
||||||
cc:
|
cc:
|
||||||
type: list
|
type: list
|
||||||
description:
|
description:
|
||||||
- a list of email addresses to cc
|
- A list of email addresses to cc.
|
||||||
bcc:
|
bcc:
|
||||||
type: list
|
type: list
|
||||||
description:
|
description:
|
||||||
- a list of email addresses to bcc
|
- A list of email addresses to bcc.
|
||||||
attachments:
|
attachments:
|
||||||
type: list
|
type: list
|
||||||
description:
|
description:
|
||||||
- a list of relative or explicit paths of files you want to attach (7MB limit as per SendGrid docs)
|
- A list of relative or explicit paths of files you want to attach (7MB limit as per SendGrid docs).
|
||||||
from_name:
|
from_name:
|
||||||
type: str
|
type: str
|
||||||
description:
|
description:
|
||||||
- the name you want to appear in the from field, i.e 'John Doe'
|
- The name you want to appear in the from field, i.e 'John Doe'.
|
||||||
html_body:
|
html_body:
|
||||||
description:
|
description:
|
||||||
- whether the body is html content that should be rendered
|
- Whether the body is html content that should be rendered.
|
||||||
type: bool
|
type: bool
|
||||||
default: 'no'
|
default: 'no'
|
||||||
headers:
|
headers:
|
||||||
type: dict
|
type: dict
|
||||||
description:
|
description:
|
||||||
- a dict to pass on as headers
|
- A dict to pass on as headers.
|
||||||
body:
|
body:
|
||||||
type: str
|
type: str
|
||||||
description:
|
description:
|
||||||
- the e-mail body content
|
- The e-mail body content.
|
||||||
required: yes
|
required: yes
|
||||||
author: "Matt Makai (@makaimc)"
|
author: "Matt Makai (@makaimc)"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = r'''
|
||||||
- name: Send an email to a single recipient that the deployment was successful
|
- name: Send an email to a single recipient that the deployment was successful
|
||||||
community.general.sendgrid:
|
community.general.sendgrid:
|
||||||
username: "{{ sendgrid_username }}"
|
username: "{{ sendgrid_username }}"
|
||||||
|
@ -120,6 +120,8 @@ EXAMPLES = '''
|
||||||
import os
|
import os
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
from distutils.version import LooseVersion
|
||||||
|
|
||||||
SENDGRID_IMP_ERR = None
|
SENDGRID_IMP_ERR = None
|
||||||
try:
|
try:
|
||||||
import sendgrid
|
import sendgrid
|
||||||
|
@ -155,6 +157,9 @@ def post_sendgrid_api(module, username, password, from_address, to_addresses,
|
||||||
'Accept': 'application/json'}
|
'Accept': 'application/json'}
|
||||||
return fetch_url(module, SENDGRID_URI, data=encoded_data, headers=headers, method='POST')
|
return fetch_url(module, SENDGRID_URI, data=encoded_data, headers=headers, method='POST')
|
||||||
else:
|
else:
|
||||||
|
# Remove this check when adding Sendgrid API v3 support
|
||||||
|
if LooseVersion(sendgrid.version.__version__) > LooseVersion("1.6.22"):
|
||||||
|
module.fail_json(msg="Please install sendgrid==1.6.22 or lower since module uses Sendgrid V2 APIs.")
|
||||||
|
|
||||||
if api_key:
|
if api_key:
|
||||||
sg = sendgrid.SendGridClient(api_key)
|
sg = sendgrid.SendGridClient(api_key)
|
||||||
|
|
Loading…
Reference in a new issue