เปิดการบันทึกกิจกรรมของลูกค้า SMTP
Contents
[
Hide
]
Aspose.Email for Python ผ่าน .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)