使用Google的Audit API监控Google Apps应用程序电子邮件

时间:2011-03-23 01:34:05

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

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

我希望管理员有办法点击我的用户发送电子邮件的视图,但事实并非如此。

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

更新!这一点500点!

我在onoku上托管应用程序的rails上使用ruby。该电子邮件完全托管谷歌应用程序标准,而不是业务,因此我们将不得不进行升级,并且如果您使用heroku,则DNS已经与zerigo一起使用。

1 个答案:

答案 0 :(得分:8)

好吧,我没有计划扩展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

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