简体   繁体   English

Lotus Notes Java API。 邮件转发

[英]Lotus Notes Java API. Mail forwarding

I would like to forward emails from my Lotus Notes inbox to my gmail account. 我想将电子邮件从我的Lotus Notes收件箱转发到我的gmail帐户。

Lotus Notes rules and agents are disabled on our server, so I developed external application for that. Lotus Notes规则和代理在我们的服务器上被禁用,因此我为此开发了外部应用程序。 I am using document.send method and mail successfully arrives to my gmail box. 我正在使用document.send方法,并且邮件成功到达了我的Gmail邮箱。 The only problem is that often the email also duplicated in my Lotus Notes inbox. 唯一的问题是,电子邮件经常也在我的Lotus Notes收件箱中重复。 I just found that the reason of that is "CC" and "BCC" fields, which I don't clean up, however, I am looking for the way to forward email as it is - which means keep original CC and BCC and TO fields - exactly on the same way as it is done by forwarding agent. 我只是发现原因是我没有清理“ CC”和“ BCC”字段,但是,我正在寻找一种直接转发电子邮件的方式-这意味着保留原始CC,BCC和TO字段-与转发代理完全相同。

I am using "IBM Notes 9" on Windows 7 64 bit. 我在Windows 7 64位上使用“ IBM Notes 9”。

I've prepared a code sample that demonstrates what I am doing. 我已经准备了一个代码样本来演示我在做什么。

package com.example;

import lotus.domino.*;

public class TestMailForwarder {
    public static void main(String[] args) throws NotesException {
        NotesThread.sinitThread();
        try {
            Session notesSession = NotesFactory.createSession(
                    (String) null, (String) null, Consts.NOTES_PASSWORD);
            DbDirectory dir = notesSession.getDbDirectory(Consts.NOTES_SERVER);
            Database mailDb = dir.openDatabaseByReplicaID(Consts.MAILDB_REPLICA_ID);
            forwardAllEmails(mailDb);
        } finally {
            NotesThread.stermThread();
        }
    }

    private static void forwardAllEmails(Database mailDb) throws NotesException {
        View inbox = mailDb.getView("$Inbox");
        //noinspection LoopStatementThatDoesntLoop
        for (Document document = inbox.getFirstDocument(); 
                 null != document; 
                 document = inbox.getNextDocument(document)) {
            document.send(Consts.GMAIL_ADDRESS);
            break;
        }
    }
}

Instead of trying to send the messages to your GMail, why not upload them using Gmail's IMAP interface. 与其尝试将邮件发送到您的GMail,不如使用Gmail的IMAP界面上传邮件。 You would require to get the message as MIME content - which probably they are already for external incoming eMails and then push them to GMail. 您可能需要将消息作为MIME内容获取-可能它们已经用于外部传入电子邮件,然后将其推送到GMail。 I don't have a ready code sample, just one for the opposite pulling GMail into Notes , but you should be able to use that as a starting point. 我没有现成的代码示例,仅一个相反的示例将GMail放入Notes ,但是您应该可以将其用作起点。

A code sample for the MIME conversion is in an IBM Technote . MIME转换的代码示例在IBM Technote中

Hope that helps 希望能有所帮助

You can't do a transparent forward with code running at the client level. 您不能对在客户端级别运行的代码进行透明转发。 Pure SMTP systems do it by preserving the RFC-822 header content while altering the RFC-821 RCPT TO data. 纯SMTP系统通过保留RFC-822标头内容,同时更改RFC-821 RCPT TO数据来做到这一点。 Domino does not give client-level code independent control over these. Domino不会为客户级代码提供对这些代码的独立控制。 It just uses the SendTo, CopyTo, and BlindCopyTo items. 它仅使用SendTo,CopyTo和BlindCopyTo项目。 (There are some tricks that mail management and archiving vendors play in order to do things like this, but they require special changes to the Domino server's router configuration, and software on the other end as well. (做这些事情,邮件管理和归档供应商发挥了一些技巧,但是它们需要对Domino服务器的路由器配置以及另一端的软件进行特殊更改。

Another way of accomplishing this (in response to the question you asked in your comment) would be to have your Java code make a direct connection to the gmail SMTP servers. 完成此操作的另一种方法(针对您在评论中提出的问题)是使Java代码直接与gmail SMTP服务器建立连接。 I'm not sure how easy it is. 我不确定这有多容易。 A comment on this question states that the Java Mail API allows you to control the RCPT TO separately from the RFC822 headers, but I've not looked into the specifics other than taking note that there's an SMTPTransport class -- which is where I'd look for anything related to RFC-821 protocol. 关于此问题的评论指出,Java Mail API允许您与RFC822标头分开控制RCPT TO,但是除了注意有一个SMTPTransport类之外,我没有研究其他细节-这是我要在的地方寻找与RFC-821协议有关的任何内容。 The bigger issue is that you will have to take control of converting messages into MIME format. 更大的问题是,您将必须控制将邮件转换为MIME格式。 With Notes mail, you may have a mix of Notes rich text and MIME. 使用Notes邮件,您可能会混合使用Notes RTF和MIME。 Theres a convertToMIME method in Notes 8.5.1 and above, but this will only convert the message body. 在Notes 8.5.1及更高版本中有一个convertToMIME方法 ,但这只会转换消息正文。 You'll have to deal with any header content separately. 您必须单独处理任何标题内容。 (I'm not really up to speed on Notes 9, but AFAIK even though there is functionality in the client to create a .EML file when you drag a message to the desktop, there's no API there to do that for you.) (我并没有真正加快Notes 9的速度,但是AFAIK即使将消息拖放到桌面时客户端中具有创建.EML文件的功能,也没有API可以为您做这件事。)

Finally, I've found a ready solution: AWESYNC.MAIL . 最后,我找到了一个可用的解决方案: AWESYNC.MAIL It is a commercial software but it does exactly what I need. 它是一种商业软件,但确实可以满足我的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM