gpt4 book ai didi

ruby - 邮寄 gem : how to set an email to "read"?

转载 作者:太空宇宙 更新时间:2023-11-03 16:33:29 26 4
gpt4 key购买 nike

我必须用 Ruby 编写一个电子邮件导入程序,我偶然发现了 Ruby 1.9 的非常漂亮的 Mail gem。我知道如何遍历未读消息,但我不知道如何将它们标记为已读(文档很详尽,但我真的不知道要注意什么):

Mail.defaults do
retriever_method :imap,
address: email_account.email_server.host,
port: email_account.email_server.port,
user_name: email_account.address,
password: email_account.password,
enable_ssl: email_account.email_server.ssl
end

emails = Mail.find(
what: :first,
count: 3,
order: :asc
)

emails.each do |email|
# Do some stuff and then mark as read!
end

最佳答案

做起来很简单

Mail.defaults do
retriever_method :imap,
address: email_account.email_server.host,
port: email_account.email_server.port,
user_name: email_account.address,
password: email_account.password,
enable_ssl: email_account.email_server.ssl
end

Mail.find(what: :first, count: 3, order: :asc) do |email, imap, uid|
# Do some stuff
# ..
# mark as read
imap.uid_store( uid, "+FLAGS", [Net::IMAP::SEEN] )
end

关于ruby - 邮寄 gem : how to set an email to "read"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11736829/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com