0

我想将开始日期和结束日期的时区更改为 CST(美国/中部时间),我在此处编码的时间会自动转换为本地时间,因此在将其放入本地时间后会更改appointment.Start = "yyyy-MM-dd hh:mm:ss" 。我还想知道如何将这次约会的发件人更改为我将提供的 gmail。因为appointment.Organizer = "gmail"不工作也不appointment.SendUsingAccount = "gmail"

这是代码:

acc = ""
for account in session.Accounts:
    if account.AccountType == 1: #0 - outlookExchange, 1 - outlookIMAP, 2 - outlookPop3
        print(account)
        acc = account

def saveMeeting(start, end, subject, location, attachments, recipients):

    appointment = outlook.CreateItem(1) #1 - AppointmentItem

    # Fill in the data needed
    appointment.SendUsingAccount = acc
    appointment.StartTimeZone = outlook.TimeZones("Central Standard Time")
    appointment.Start = start #yyyy-MM-dd hh:mm:ss
    appointment.EndTimeZone = outlook.TimeZones("Central Standard Time")
    appointment.End = end #yyyy-MM-dd hh:mm:ss
    appointment.Subject = subject
    appointment.Location = location
    appointment.MeetingStatus = 1 

    if attachments != '':
        appointment.Attachments.Add(attachments)

    recipients = filter(None, recipients)

    for recipient in recipients:
        appointment.Recipients.Add(recipient) 

    appointment.Save()

    # Only use .Display() if using tkinter
    appointment.Display()
4

1 回答 1

0

要设置时区,您需要使用TimeZones界面,该界面代表 Microsoft Windows 中识别的所有时区。它还使用TimeZone对象来设置或获取对象的StartTimeZone属性和EndTimeZone属性AppointmentItem。下面是示例 VB 代码,它显示了如何在 Outlook 约会中设置时区:

Private Sub TimeZoneExample()
    Dim appt As Outlook.AppointmentItem = _
        CType(Application.CreateItem( _
        Outlook.OlItemType.olAppointmentItem), Outlook.AppointmentItem)
    Dim tzs As Outlook.TimeZones = Application.TimeZones
    ' Obtain timezone using indexer and locale-independent key
    Dim tzEastern As Outlook.TimeZone = tzs("Eastern Standard Time")
    Dim tzPacific As Outlook.TimeZone = tzs("Pacific Standard Time")
    appt.Subject = "SEA - JFK Flight"
    appt.Start = DateTime.Parse("8/9/2006 8:00 AM")
    appt.StartTimeZone = tzPacific
    appt.End = DateTime.Parse("8/9/2006 5:30 PM")
    appt.EndTimeZone = tzEastern
    appt.Display(False)
End Sub

如果您gmail在 Outlook 配置文件中配置了帐户,则可以使用AppointmentItem.SendUsingAccount属性。

SendUsingAccount这是 VBA 示例,它显示了如何在 Outlook中设置属性:

Sub SendUsingAccount() 
 Dim oAccount As Outlook.account 
 For Each oAccount In Application.Session.Accounts 
   If oAccount.AccountType = olPop3 Then 
     Dim oMail As Outlook.MailItem 
     Set oMail = Application.CreateItem(olMailItem) 
     oMail.Subject = "Sent using POP3 Account" 
     oMail.Recipients.Add ("someone@example.com")  
     oMail.Recipients.ResolveAll  
     Set oMail.SendUsingAccount = oAccount  
     oMail.Send  
   End If  
 Next  
End Sub
于 2022-01-31T15:46:20.660 回答