MCP Notmuch Sendmail 作为您的邮件助手,将 Claude 桌面版与您的 notmuch 邮件数据库连接起来,让您可以便捷地搜索、浏览、编写和管理邮件,极大提升邮件处理效率。
pip install markdown-it-py html2text python-notmuch
python3 mcp_sendmail.py
pip install markdown-it-py html2text python-notmuch
python3 mcp_sendmail.py
在 config.py 文件中填写您的 SMTP 服务器信息:
_SMTP_SERVER = 'smtp.example.com'
_SMTP_PORT = 587
_SMTP_USERNAME = 'your_email@example.com'
_SMTP_PASSWORD = 'your_password'
# 发送纯文本邮件
send_plain_text("收件人邮箱", "邮件主题", "邮件正文内容")
# 发送 HTML 格式邮件
send_html_email("收件人邮箱", "邮件主题", "HTML 邮件
这是 HTML 格式的邮件正文。
", ["attachment1.pdf"])
def send_plain_text(to, subject, body):
msg = MIMEText(body)
msg['Subject'] = subject
msg['From'] = _SMTP_USERNAME
msg['To'] = to
with smtplib.SMTP(_SMTP_SERVER, _SMTP_PORT) as server:
server.starttls()
server.login(_SMTP_USERNAME, _SMTP_PASSWORD)
server.sendmail(_SMTP_USERNAME, [to], msg.as_string())
def send_html_email(to, subject, html_content, attachments=None):
msg = MIMEMultipart('alternative')
msg.attach(MIMEText('', 'plain', 'utf-8'))
templateLoader = jinja2.FileSystemLoader(searchpath="./templates")
templateEnv = jinja2.Environment(loader=templateLoader)
template = templateEnv.get_template("email_template.html")
output_text = template.render()
part = MIMEText(output_text, 'html')
msg.attach(part)
if attachments:
for attachment in attachments:
with open(attachment, 'rb') as file:
part = MIMEBase('application', 'octet-stream')
part.set_payload(file.read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', f'attachment; filename="{os.path.basename(attachment)}"')
msg.attach(part)
with smtplib.SMTP(_SMTP_SERVER, _SMTP_PORT) as server:
server.starttls()
server.login(_SMTP_USERNAME, _SMTP_PASSWORD)
server.sendmail(_SMTP_USERNAME, [to], msg.as_string())
mcp_sendmail/
├── sendmail.py # 邮件发送核心逻辑
├── templates/ # HTML 邮件模板文件夹
│ └── email_template.html # 示例 HTML 邮件模板
└── config.py # SMTP 服务器配置信息
通过 MCP Notmuch Sendmail,让 Claude 桌面版成为您强大的邮件管理工具。