[英]Rails ActionMailer copy email to sent folder SMTP ruby
Hi I can send the email I want using the send mail function but No sent mail appears in the clients sent folder.您好,我可以使用发送邮件功能发送我想要的电子邮件,但是客户端发送的文件夹中没有显示已发送的邮件。
Do I have to manually copy the email to the sent folder somehow?我是否必须以某种方式手动将电子邮件复制到已发送文件夹? The config is below and works sending emails, just for reference配置如下,可以发送邮件,仅供参考
config.action_mailer.smtp_settings = {
address: 'send.XXX.com',
port: 587,
domain: 'XXX.com',
user_name: 'X@XXX.com',
password: 'XXX',
authentication: 'plain',
enable_starttls_auto: true }
How can I do this in Rails我怎样才能在 Rails 中做到这一点
Update更新
Can be done easily with IMAP, just make a new mail, Mail.new etc then可以使用 IMAP 轻松完成,只需创建新邮件、Mail.new 等即可
target_mailbox = 'Inbox.Sent'
imap = Net::IMAP.new("imap.someserver.com")
imap.authenticate(email_account.authentication, email_account.user_name, email_account.password)
imap.create(target_mailbox) unless imap.list('', target_mailbox)
imap.append(target_mailbox, imap_sent_mail_copy.to_s)
imap.logout
imap.disconnect
target_mailbox = 'Inbox.Sent'
imap = Net::IMAP.new("imap.someserver.com")
imap.authenticate(email_account.authentication, email_account.user_name, email_account.password)
imap.create(target_mailbox) unless imap.list('', target_mailbox)
imap.append(target_mailbox, imap_sent_mail_copy.to_s)
imap.logout
imap.disconnect
where imap_sent_mail_copy.to_s is simply a Mail instance其中 imap_sent_mail_copy.to_s 只是一个 Mail 实例
imap_sent_mail_copy = Mail.new do
to to_email_address
from from
subject subject
message_id message_id
if attachment_ids!=""
docs = Document.where(id: attachment_ids)
docs.each do |a|
doc = Document.find_by_id(a)
attachments["#{doc.name}.#{doc.file_ext}"] = File.read("#{Rails.root}/public#{doc.attachment_url}") if doc
end
end
html_part do
content_type 'text/html; charset=UTF-8'
body "#{message} #{signature}"
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.