ruby-on-rails - 使用 Google 的 Audit API 监控 google 应用程序电子邮件

标签 ruby-on-rails monitor google-email-audit-api

我需要让一些使用谷歌应用 gmail 的管理员用户能够监控他们的员工电子邮件。您是否使用过 Google 的 Audit API 来执行此操作。

我希望管理员可以通过单击查看我的用户电子邮件的方法,但事实并非如此。

如果重要的话,应用程序就是一个 rails 应用程序。电子邮件完全通过谷歌应用程序在谷歌邮件上完成。任何这样做过的人,任何建议都会有所帮助。

更新!这个500分!

我正在使用 ruby​​ on rails 在 heroku 上托管一个应用程序。该电子邮件完全由谷歌应用程序标准托管,而不是业务,因此我们必须升级,并且 DNS 使用 zerigo,如果您使用 heroku,您已经知道。

最佳答案

嗯,我没有计划延长 gdata-ruby-util gem :),但这里有一些代码可用于基于 Google 的 documentation 的 Google Audit API .我只写了一个 create_monitor_on 方法,其余的都很容易获得。

让我知道它是否有效或需要任何重写,我会在这里更新它:

    class Audit < GData::Client::Base

      attr_accessor :store_at

      def initialize(options = {})
        options[:clientlogin_service] ||= 'apps'
        options[:authsub_scope] ||= 'https://apps-apis.google.com/a/feeds/compliance/audit/' 
        super(options)
      end

      def create_monitor_on(email_address)
        user_name, domain_name = email_address.split('@')
        entry = <<-EOF
        <atom:entry xmlns:atom='http://www.w3.org/2005/Atom' xmlns:apps='http://schemas.google.com/apps/2006'>
        <apps:property name='destUserName' value='#{@store_at}'/>
        <apps:property name='beginDate' value=''/>
        <apps:property name='endDate' value='2019-06-30 23:20'/>
        <apps:property name='incomingEmailMonitorLevel' value='FULL_MESSAGE'/>
        <apps:property name='outgoingEmailMonitorLevel' value='FULL_MESSAGE'/>
        <apps:property name='draftMonitorLevel' value='FULL_MESSAGE'/>
        <apps:property name='chatMonitorLevel' value='FULL_MESSAGE'/>
        </atom:entry>
        EOF

        return true if post('https://apps-apis.google.com/a/feeds/compliance/audit/mail/monitor/'+domain_name+'/'+user_name, entry).status_code == 201
        false
      end   
   end

然后像这样在其他地方使用它:

auditor = Audit.new
auditor.store_at = 'this-username'
auditor.clientlogin(username, password)
render :success if auditor.create_monitor_on('email-address@my-domain.com')

我的建议是创建一个所有电子邮件监控器都发送到的核心电子邮件地址,这样您的管理员的收件箱就不会被其他人的邮件塞满。然后在您的 Rails 应用程序中,使用 Net::IMAP 从该主电子邮件帐户下载您想要的消息。即,您可以创建一个显示“查看 Joe 的电子邮件”的链接,该方法执行以下操作:

require 'net/imap'

imap = Net::IMAP.new('imap.gmail.com', 993, true)
imap.login('this-username@my-domain.com', password)
imap.select('INBOX')

messages = []
imap.search(["TO", "joe@email.com").each do |msg_id|
  msg = imap.fetch(msg_id, "(UID RFC822.SIZE ENVELOPE BODY[TEXT])")[0]
  body = msg.attr["BODY[TEXT]"]
  env = imap.fetch(msg_id, "ENVELOPE")[0].attr["ENVELOPE"]
  messages << {:subject => env.subject, :from => env.from[0].name, :body => body }
end

imap.logout
imap.disconnect

然后您可以将这些消息放在您的 View 中 - 或者将它们全部发送到一封批量电子邮件中,或者您想做的任何事情。

关于ruby-on-rails - 使用 Google 的 Audit API 监控 google 应用程序电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5399914/

相关文章:

ruby-on-rails - 在 lib 目录的模块中使用类 - Rails 3

c# - 最近的 OpenHardwareMonitor 示例代码 C#

azure - 如何在 Azure 监视器中添加 VM 洞察指标警报?

php - 使用电子邮件审核(Admin SDK)下载邮箱

ruby-on-rails - 如何将 SQL Server TableView 用作 Rails 模型(只读)?

ruby-on-rails - Rails - 放置非 Active Record 模型的位置(目录)

ruby-on-rails - Capistrano 中 current_path 与 release_path 的区别?

ios - CLLocationManager 的区域监控 vs 重大位置变化

node.js - 使用 Node.js 和 HTTPS 进行电子邮件审核 API 时参数太长