用于使用发送服务器创建 Mail.app 帐户的 Applescript 出错 - 增加隐藏副本

Applescript for creating a Mail.app account with outgoing server goes wrong - multiply hidden copies

提问人:iPadawan 提问时间:11/8/2023 最后编辑:iPadawan 更新时间:11/8/2023 访问量:27

问:

让我们使用 Applescript 做基本操作。 我尝试创建一个邮件帐户。(过去我确实得到了一些东西,但现在它不起作用。

如果我创建一个帐户,我确实会在控制台中返回一个 ID,但它永远不会显示在 Mail.app 中。为什么???我确实读过一些关于幽灵帐户和服务器的文章。 如果我使用代码检查帐户列表,则帐户就在那里。 再次运行创建帐户代码,我得到了两个该帐户(每次运行都会添加一个相同的帐户)。为什么??? 当我退出邮件并重新启动邮件时,它们就不再存在了。 还有最后一点,为什么没有创建 smtp 服务器?

最后,我确实把所有这些代码片段都收集起来,看看出了什么问题;但老实说“我不知道”

但是我先使用代码删除现有帐户(Ghost帐户)时出现错误(见图)enter image description here

出了什么问题,是我的代码还是Applescript或 Mail.app 中的错误?

set accountName to "[email protected]"
set accountUser to accountName
set accountServer to "imap.mailhosted.nl"
set accountPort to 993 --995 
set accountSSL to true
set accountType to "imap"
set fullName to accountName
set emailAddress to accountName
set deleteMail to false -- do not quote

set myPassword to "mypassword"

-- Optional SMTP account details - not always easy to add later:
set smtpUser to accountName
set smtpServer to "smtp.mailhosted.nl"
set smtpPort to 465
set smtpSSL to "YES"
set useAuthentication to "YES"
set smtpAuth to "PASSWORD"

set stopScript to false
tell application "Mail"
    activate
    delay 5
    (* get and show all the accounts *)
    set accntList to ""
    repeat with anAccount in every account
        set accntList to accntList & "All accounts -- Name: " & name of anAccount & "
" & "User name: " & user name of anAccount & "
" & "Type: " & account type of anAccount & "
" & "Email addresses: " & email addresses of anAccount & "
        
"
    end repeat
    display alert accntList
    
    
    (* check if the new account exists *)
    if account accountName exists then
        display dialog "Account '" & accountName & "' already exists. Delete them and stop" buttons {"Stop script"} with icon stop
        set stopScript to true
        
        repeat with anAccount in every account
            set accntList to ""
            if name of anAccount is accountName then
                set accntList to "Existing account -- Name: " & name of anAccount & "
" & "User name: " & user name of anAccount & "
" & "Type: " & account type of anAccount & "
" & "Email addresses: " & email addresses of anAccount
                (* show and delete *)
                display alert accntList
                delete anAccount
                exit repeat
            end if
        end repeat
        
        
    end if
    if stopScript is false then
        try
            display alert "Try to create an Account for : " & accountName
            set newacct to make new imap account with properties {name:accountName, user name:accountName, password:myPassword, uses ssl:true, server name:accountServer, port:accountPort, full name:accountName, email addresses:{accountName}}
            
            set accntList to ""
            set accntList to "New Account -- Name: " & name of newacct & "
" & "User name: " & user name of newacct & "
" & "Type: " & account type of newacct & "
" & "Email addresses: " & email addresses of newacct
            (* show new account *)
            display alert accntList
            
            (* Create a new SMTP server in the list. *)
            set addsmtp to make new smtp server with properties {server name:"xxx.mycompany.com", user name:"[email protected]", uses ssl:true, authentication:password, password:""}
            set smtp server of newacct to addsmtp
            
        end try
    end if
    
end tell

顺便说一句,它确实对流行邮件帐户做了同样的事情。 有人看到我的问题并能够帮助我吗?我真的很感激。谢谢

macOS 电子邮件 AppleScript

评论


答: 暂无答案