【问题标题】:How to resolve an issue with sending message to SMTP Server (mailR+Outlook)如何解决将邮件发送到 SMTP 服务器 (mailR+Outlook) 的问题
【发布时间】:2021-10-09 14:36:07
【问题描述】:

我一直在设置mailR包从我的Outlook帐户发送电子邮件,但到目前为止我一直无法使其顺利工作,我得到结果有时发送电子邮件成功有时失败。

代码如下(为了隐私/安全,将电子邮件和密码替换为“aaa”和“bbb”):

  send.mail(from = "aaa@domain.com",
            to = "bbb@domain.com",
            subject = subject,
            body = 'Test Successful',
            encoding = 'utf-8',
            html = TRUE,
            inline = TRUE,
            attach.files = filenamex,
            smtp = list(host.name = 'smtp.office365.com',
                        port = 587,
                        user.name="aaa@domain.com",
                        passwd= "abc",
                        tls = TRUE                       
            ),
            authenticate = TRUE,
            send = TRUE)

当我每隔 5 分钟运行一次代码时,我得到以下结果

2. send email at 2021-10-04 20:55:01 +07 failed !
1. send email at 2021-10-04 21:00:01 +07 successful !
2. send email at 2021-10-04 21:05:01 +07 failed !
2. send email at 2021-10-04 21:10:02 +07 failed !
2. send email at 2021-10-04 21:15:01 +07 failed !
1. send email at 2021-10-04 23:03:09 +07 successful !
2. send email at 2021-10-04 23:05:01 +07 failed !
1. send email at 2021-10-04 23:10:01 +07 successful !
2. send email at 2021-10-04 23:15:01 +07 failed !
1. send email at 2021-10-04 23:20:01 +07 successful !
1. send email at 2021-10-04 23:25:01 +07 successful !
1. send email at 2021-10-04 23:30:02 +07 successful !

知道出了什么问题吗?

【问题讨论】:

    标签: r email outlook


    【解决方案1】:

    RDCOMClient 示例:

    install.packages("RDCOMClient", repos = "http://www.omegahat.net/R")
    #or devtools::install_github("omegahat/RDCOMClient")
    
    # Load the DCOM library
    library (RDCOMClient)
    
    # Open Outlook
    Outlook <- COMCreate("Outlook.Application")
    
    # Create a new message
    Email = Outlook$CreateItem(0)
    
    # Set the recipient, subject, and body
    Email[["to"]] = "recipient1@test.com; recipient2@test.com; 
    recipient3@test.com"
    Email[["cc"]] = ""
    Email[["bcc"]] = ""
    Email[["subject"]] = "Quarterly Sales Analysis Updated"
    Email[["body"]] = 
    "The quarterly sales analysis has been updated.  
    You can find it at: D:\\Reports\\Sales Analysis.xlsx"
    
    # Send the message
    Email$Send()
    
    # Close Outlook, clear the message
    rm(Outlook, Email)
    

    查看更多there

    以 emayili 为例

    library(emayili)
    
    #making an email
    email <- envelope() %>%
    from("user@sender.com") %>%
    to(c("Recipient 1 <user1@recipient.com>", "Recipient 2 
    <user@recipient.com>")) %>%
    cc("cc@recipient.com") %>%
    bcc("bcc@recipient.com") %>%
    reply("reply-to@recipient.com") %>%
    subject("Test email subject") %>%
    body("Test email body")
    
    #configuring the SMTP
    smtp <- server(host = "smtp.mailtrap.io",
            port = 25,
            username = "********",
            password = "*********")
    
    #sending    
    smtp(email, verbose = TRUE)
    

    查看更多there

    【讨论】:

    • 感谢 Manro,问题仍然存在。
    • @nguyen.hoang 我可以看到MailR 包已过时(上次更新是 6 年前)。尝试使用RDCOMClient(如果您使用 Outlook)。我在上面添加了一个示例。
    • @nguyen.hoang ... 或library(emayili)
    猜你喜欢
    • 1970-01-01
    • 2016-02-09
    • 2013-08-20
    • 2021-12-01
    • 2022-11-12
    • 2016-12-18
    • 1970-01-01
    • 2014-03-08
    • 1970-01-01
    相关资源
    最近更新 更多