win32com未发送附件

2024-04-27 20:26:02 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的第一个问题,所以我希望没问题。在

我试图用win32com和outlook2010发送一封带有Python附件的电子邮件。它发送电子邮件。但它没有发送附件。我的代码基于这里给出的一个例子。在

def email_tamplate(*args):
  Format = { 'UNSPECIFIED' : 0, 'PLAIN' : 1, 'HTML' : 2, 'RTF'  : 3}
  profile = "Outlook"
  #session = win32com.client.Dispatch("Mapi.Session")
  outlook = win32com.client.Dispatch("Outlook.Application")
  #session.Logon(profile)
  mainMsg = outlook.CreateItem(0)
  mainMsg.To = str(login_entry.get())+"@amazon.com"
  mainMsg.Subject = "Sauron personal report request between "+str(start_date.get())+" and "+str(end_date.get())
  mainMsg.BodyFormat = Format['RTF']
  mainMsg.HTMLBody = body

  try:
    attachment1= ('C:\\Users\\' + str(login_entry.get()) + '\\My Documents\\status_email.csv')
    mainMsg.Attachments.Add(attachment1)
  except:
    pass                                   

  mainMsg.Send()

以下是我在不使用Try/except时收到的错误消息:

Exception in Tkinter callback Traceback (most recent call last): File "C:\Python33\lib\tkinter__init__.py", line 1475, in call return self.func(*args) File "C:\Users\alvaros\Dev\Sauron\v2\Sauron v2.2.1.py", line 478, in status_email email_tamplate() File "C:\Users\alvaros\Dev\Sauron\v2\Sauron v2.2.1.py", line 424, in email_tamplate mainMsg.Attachments.Add(attachment1) File ">", line 3, in Add pywintypes.com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft Outlook', "You don't have appropriate permission to perform this operation.", None, 0, -2147024891), None)

除了附件没有被发送之外,一切都正常。附件的路径是正确的,并且文件在那里。在

谢谢。在


Tags: inadd附件getemaillineuserswin32com
2条回答

您可能需要以管理员身份运行该程序,或者如果无法运行,则[在此处输入链接说明][1]您可能需要使用“Extended MAPI”来运行此程序:

另一方面,这个线程讨论了如何编辑PST文件本身的属性或在Windows注册表中编辑其属性:

这已经解决了。 谢谢你的帮助。 可能是缩进的问题。因为它基本上是自己解决的。在

相关问题 更多 >