Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

tgpdc-mailer

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tgpdc-mailer

A simple package for sending templated emails using Microsoft Graph API

pipPyPI
Version
0.1.2
Maintainers
1

Tgpdc Mailer

PyPI version License: MIT Python 3.7+

A simple Python package for sending templated emails using Microsoft Graph API.

📋 Table of Contents

✨ Features

  • 📧 Send HTML templated emails using Microsoft Graph API
  • 🔄 Simple template variable substitution
  • 👥 Support for multiple recipients, CC, and BCC
  • ⚙️ Environment variable configuration support
  • 🚀 Easy-to-use API

📥 Installation

pip tgpdc-mailer

📝 Prerequisites

  • Microsoft Azure Account
  • Registered Application in Azure AD with permissions:
    • Mail.Send
    • Mail.Send.Shared

⚙️ Configuration

Environment Variables

Create a .env file:

TENANT_ID=your_tenant_id
CLIENT_ID=your_client_id
CLIENT_SECRET=your_client_secret
SENDER_EMAIL=your_sender_email@domain.com

Direct Initialization

from tgpdc_mailer import Mailer

mailer = Mailer(
    tenant_id="your_tenant_id",
    client_id="your_client_id",
    client_secret="your_client_secret",
    sender_email="your_sender_email@domain.com"
)

🚀 Usage

Basic Example

from tgpdc_mailer import Mailer

# Initialize the mailer
mailer = Mailer()

# Send email
result = mailer.send_email(
    to_emails="recipient@example.com",
    subject="Welcome Email",
    template_path="templates/welcome.html",
    template_context={
        "name": "John Doe",
        "company": "ACME Corp"
    }
)

📝 Examples

Template Structure

<!DOCTYPE html>
<html>
<body>
    <h1>Welcome {{ name }}!</h1>
    <p>Thank you for joining {{ company }}.</p>
</body>
</html>

Multiple Recipients

result = mailer.send_email(
    to_emails=[
        "recipient1@example.com",
        "recipient2@example.com"
    ],
    subject="Team Update",
    template_path="templates/update.html",
    template_context={
        "update_text": "New project starting next week"
    },
    cc_emails=["manager@example.com"],
    bcc_emails=["archive@example.com"]
)

Error Handling

result = mailer.send_email(
    to_emails="recipient@example.com",
    subject="Test Email",
    template_path="templates/notification.html",
    template_context={"message": "Hello World!"}
)

if result['success']:
    print("Email sent successfully!")
else:
    print(f"Failed to send email: {result['message']}")

🔧 Troubleshooting

Common Issues

IssueSolution
Authentication FailedCheck Azure AD credentials and permissions
Template Not FoundVerify template path and file existence
Invalid RecipientsValidate email address format

📄 License

Distributed under the MIT License. See LICENSE for more information.

🙏 Acknowledgments

  • Microsoft Graph API
  • Python Requests Library
  • Python-dotenv

📝 Version History

VersionChanges
0.1.1Initial Release

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts