Mailgun Class¶
Mailgun¶
Mailgun class to send email and get extracted data
-
class
mailgun.mailgun.
Mailgun
(apikey: str = None, domain: str = None, version: str = 'v3')[source]¶ Bases:
object
Initializes an object of Mailgun class.
- Args:
- apiKey:
str
- API key provided from mailgun. You can also save env var as
MAILGUN_API_KEY
. - domain:
str
- domain to use for this class. You can also save env var as
MAILGUN_DOMAIN
. - version:
str
- Maingun API version.
- apiKey:
- Returns:
- Mailgun class object.
-
get_logs
(params: dict = {'event': 'stored'})[source]¶ Logs
- Args:
- Params:
dict
- filter for logs.
- Params:
- Return:
- logs dicts:
dict
-
get_message_mime
(url: str)[source]¶ get email mime to parse email
- Args:
- url:
str
- image storage url
- url:
- Return:
- json with body-mime:
dict
-
mailing_list_add_email
(list_name: str, data: dict)[source]¶ Add user to mailing list
- Args:
list_name:
str
data:dict
data of user
{'subscribed': True, 'address': 'bar@example.com', 'name': 'Bob Bar', 'description': 'Developer', 'vars': '{"age": 26}'}
- Return:
- Rsponses from API:
dict
-
mailing_list_create
(list_name: str, description: str)[source]¶ Create new mailing list
- Args:
- list_name:
str
description:str
- Return:
- Response dict:
dict
-
mailing_list_delete
(list_name: str)[source]¶ Delete mailing list
- Args:
- list_name:
str
- Return:
- Response dict:
dict
-
mailing_list_delete_email
(list_name: str, email: str)[source]¶ Delete user from mailing list
- Args:
list_name:
str
email:str
email to be removed- Return:
- Rsponses from API:
dict
-
mailing_list_update_email
(list_name: str, email: str, data: dict)[source]¶ Update user to detail on mailing list
- Args:
list_name:
str
email:str
data:dict
data of user
{'subscribed': True, 'name': 'Bob Bar', 'description': 'Developer', 'vars': '{"age": 26}'}
- Return:
- Rsponses from API:
dict
-
parse_email_mime
(body_mime, email_id: str = None, save_attachment_dir: str = 'tmp')[source]¶ parse email-mime
- Args:
- body-mime:
str
- Return:
- Metadata and file saved in tmp dir:
dict
-
send_message
(sender_email: str, to: str, subject: str, html_body: str = None, text_body: str = None, files: list = None, extra_data: dict = None)[source]¶ Send email
- Args:
- sender_email:
str
- example “Test email <test@docsumo.com>”
- to:
str
- user email id
subject:
str
html_body:str
text_body:str
files:list
list of files- extra_data:
dict
- extra data for tagging and tracking
- sender_email:
- Return:
Response from API:
json
{ 'id': '<20190714191959.1.D7B53FD6D5077D03@mg.docsumo.com>', 'message': 'Queued. Thank you.' }
Example:
send_message("Text, <test@gmail.com>", "bkrm.dahal@gmail.com", "Docsumo: Automate invoice data capture at Docsumo", "welcome_email", files=["./data.pdf])
-
send_message_template
(sender_email: str, to: str, subject: str, template_name: str, data: dict, extra_data: dict = None)[source]¶ Send email using template
- Args:
- sender_email:
str
- example “Test email <test@docsumo.com>”
- to:
str
- user email id
subject:
str
template_name:str
data:str
data for template make string from dict usingjson.dumps
- extra_data:
dict
- extra data for tagging and tracking
- sender_email:
- Return:
Response from API:
json
{ 'id': '<20190714191959.1.D7B53FD6D5077D03@mg.docsumo.com>', 'message': 'Queued. Thank you.' }
Example:
send_message_template("Text, <test@gmail.com>", "bkrm.dahal@gmail.com", "Docsumo: Automate invoice data capture at Docsumo", "welcome_email", {"company_name": "docsumo", "first_name": "bikram"})