启用 SMTP 客户端活动日志记录

Contents
[ ]

Aspose.Email for Python via .NET 提供内置的 SMTP 活动日志记录支持。此功能(通常称为活动日志记录)允许开发者系统地跟踪发送过程中的电子邮件事务、事件或错误。它在调试、审计或维护服务器端应用程序的运行透明度时特别有用。

SmtpClient 该类提供以下属性以启用和配置活动日志记录:

  • log_file_name:指定日志文件的完整路径和名称。

  • use_date_in_log_file_name:确定是否应将当前日期追加到日志文件名中,这对于创建每日日志很有用。

下面的代码示例演示了如何在程序代码中启用 SMTP 活动日志记录:

import aspose.email as ae

# Initialize and configure the SMTP client
client = ae.clients.smtp.SmtpClient
client.host = "<HOST>"
client.username = "<USERNAME>"
client.password = "<PASSWORD>"
client.port = 587
client.security_options = ae.clients.SecurityOptions.SSL_EXPLICIT

# Set the log file name and enable/disable date in file name
client.log_file_name = "C:\Aspose.Email.Smtp.log"

# Set to True to append current date
client.use_date_in_log_file_name = False

# Prepare and send the email
eml = ae.MailMessage("from address", "to address", "this is a test subject", "this is a test body")
client.send(eml)