从数据框列中提取电子邮件ids并使用R自动发送邮件的步骤如下:
library(dplyr)
library(stringr)
library(mailR)
email_ids <- df$email[str_detect(df$email, "\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}\\b")]
sender <- "your_email@example.com"
password <- "your_password"
server <- "smtp.example.com"
port <- 587
subject <- "自动发送邮件测试"
body <- "这是一封自动发送的测试邮件。"
for (email_id in email_ids) {
tryCatch({
send.mail(from = sender,
to = email_id,
subject = subject,
body = body,
smtp = list(host.name = server, port = port, user.name = sender, passwd = password, ssl = TRUE),
authenticate = TRUE,
send = TRUE)
cat("邮件发送成功至", email_id, "\n")
}, error = function(e) {
cat("邮件发送失败至", email_id, ",错误信息:", e$message, "\n")
})
}
以上是使用R从数据框列中提取电子邮件ids并自动发送邮件的步骤。在实际应用中,需要根据具体情况进行参数配置和错误处理。
领取专属 10元无门槛券
手把手带您无忧上云