我一直在設定mailR包從我的Outlook帳戶發送電子郵件,但到目前為止我一直無法讓它順利作業,我得到的結果有時發送電子郵件成功,有時失敗。
代碼如下(為了隱私/安全,將電子郵件和密碼替換為“aaa”和“bbb”):
send.mail(from = "[email protected]",
to = "[email protected]",
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="[email protected]",
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 !
知道出了什么問題嗎?
uj5u.com熱心網友回復:
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"]] = "[email protected]; [email protected];
[email protected]"
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)
在那里查看更多
emayili 示例
library(emayili)
#making an email
email <- envelope() %>%
from("[email protected]") %>%
to(c("Recipient 1 <[email protected]>", "Recipient 2
<[email protected]>")) %>%
cc("[email protected]") %>%
bcc("[email protected]") %>%
reply("[email protected]") %>%
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)
在那里查看更多
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/312929.html
