我用 Python 发送邮件有什么错误

What's mistake I do in order to send mail with Python

您好,如果 运行 此代码仅在一个文件中有效,我有一个问题。

import win32com.client as win32

outlook=win32.Dispatch('outlook.application')
mail=outlook.CreateItem(0)

mail.To='example@example.com'
mail.Subject='Message subject'
mail.Body='Message body'

mail.Send()

但是现在我需要拆分才能有一个功能,所以我这样做了。

mailCode.py

import win32com.client as win32

class multipleSendByMail:
    outlook=win32.Dispatch('outlook.application')
    mail=outlook.CreateItem(0)

    def multipleSendMail(self, destMail, msg, subject):
        for i in destMail:
            self.mail.To=destMail #'example@example.com'
            self.mail.Subject=subject #'Message subject'
            self.mail.Body=msg #'Message body'
    
            self.mail.Send()
    return True

main.py

from mailCode import *

sendMail = multipleSendByMail
destMail = ["mail1@mail.com", "mail2@mail.com"]
msg = "Messaggio"
subject = "Oggetto"
ret = sendMail.multipleSendMail(destMail, msg, subject)

但是我遇到了这个错误:

ret = sendMail.multipleSendMail(destMail, msg, subject)
TypeError: multipleSendMail() missing 1 required positional argument: 'subject'

所以我尝试这样修改主要内容:

main.py

from mailCode import *

sendMail = multipleSendByMail()
destMail = ["mail1@mail.com", "mail2@mail.com"]
msg = "Messaggio"
subject = "Oggetto"
ret = sendMail.multipleSendMail(destMail, msg, subject)

但是我遇到了这个错误:

Traceback (most recent call last):
File "C:/Users/myPath/mailSender/main.py", line 7, in <module>
    ret = sendMail.multipleSendMail(destMail, msg, subject)
  File "C:\Users\myPath\mailSender\mailCode.py", line 9, in multipleSendMail
    self.mail.To=i
  File "C:\tools\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 549, in __setattr__
    self._oleobj_.Invoke(entry.dispid, 0, invoke_type, 0, value)
pywintypes.com_error: (-2147352567, 'Eccezione.', (4096, 'Microsoft Outlook', "L'elemento è stato spostato o eliminato.", None, 0, -2147221238), None)

错误是意大利语,并说出“元素已被移动或删除”的例外情况

怎么了?我认为这是一个基本错误,但我现在看不到?

已解决。

destMail = ["mail1@mail.com", "mail2@mail.com"]

需要: destMail = "mail1@mail.com; mail2@mail.com"