You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python Web应用集成Outlook日历:设置会议邀请发件人问题

解决Outlook会议邀请指定发件人问题

Outlook的AppointmentItem没有直接的From属性,但可以通过SendUsingAccount属性指定发送会议邀请的账号,解决你遇到的发件人固定问题。

修改后的代码示例

def sendMeeting(user_email, date, start_time, title, minutes, par):
    outlook = win32com.client.Dispatch("Outlook.Application")
    appt = outlook.CreateItem(1)  # 创建AppointmentItem对象

    # 填充会议基本信息
    appt.Start = f"{date} {start_time}"  # 格式:yyyy-MM-dd hh:mm
    appt.Subject = title
    appt.Duration = int(minutes)  # Duration要求为整数(分钟数),原字符串类型会报错
    appt.Location = "Meeting Room"
    appt.MeetingStatus = 1  # 标记为会议,才能添加参会人

    # 查找并设置发件人账号
    send_account = None
    for account in outlook.Session.Accounts:
        # 匹配用户的SMTP邮箱地址
        if account.SmtpAddress.lower() == user_email.lower():
            send_account = account
            break
    
    if not send_account:
        raise ValueError(f"当前Outlook未配置邮箱 {user_email} 的账号")
    
    appt.SendUsingAccount = send_account

    # 添加参会人
    appt.Recipients.Add(par)

    appt.Save()
    appt.Send()

关键说明

  • 必须传入当前操作用户的SMTP邮箱地址(比如xxx@yourcompany.com),用于在Outlook已配置的账号中匹配对应的发送账号。
  • Duration属性需要传入整数,原代码的字符串赋值会导致Outlook接口报错,必须转换类型。
  • 运行代码的用户需确保自己的Outlook客户端已正确配置个人邮箱账号,且账号处于登录状态。

内容的提问来源于stack exchange,提问作者Ami

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 00:09:22