简体   繁体   English

Rails ActionMailer 将电子邮件复制到已发送文件夹 SMTP ruby

[英]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.

相关问题 Ruby on Rails ActionMailer SMTP设置 - Ruby on Rails ActionMailer SMTP Settings 电子邮件从Rails或actionmailer发送状态 - email sent status from rails or actionmailer Actionmailer表示已发送电子邮件,但始终无法到达(Rails 3) - Actionmailer says email sent but it never gets there (Rails 3) Ruby on Rails ActionMailer 未发送 email 且未抛出错误 - Ruby on Rails ActionMailer not sending email and not throwing error 如何使用Actionmailer / Ruby on Rails发送具有多个动态smtp的电子邮件 - How to send emails with multiple, dynamic smtp using Actionmailer/Ruby on Rails Rails:将使用prawn生成的pdf通过电子邮件发送到ActionMailer发送的电子邮件中? - Rails: Email a pdf generated with prawn to an email sent by ActionMailer? 如何使用ActionMailer在IMAP“已发送”框中保存外发电子邮件的副本? - How to save copy of outgoing email in IMAP “Sent” box using ActionMailer? Rails ActionMailer - 附加文本文件会导致电子邮件正文作为附件发送 - Rails ActionMailer - Attaching text file causes email body to be sent as attachment 尽管Rails日志表明ActionMailer未发送电子邮件,但已发送 - ActionMailer not sending email though rails logs indicate it has been sent Rails - 你如何测试 ActionMailer 在测试中发送了特定的电子邮件 - Rails - How do you test ActionMailer sent a specific email in tests
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM