You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Houman Atashbar (JIRA)" <ji...@apache.org> on 2012/10/06 03:28:02 UTC

[jira] [Commented] (NET-482) Support XOAUTH

    [ https://issues.apache.org/jira/browse/NET-482?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13470845#comment-13470845 ] 

Houman Atashbar commented on NET-482:
-------------------------------------

This is how you might use it:

public final class SMTPSMail
{

    public final static void main(String[] args)
    {
        String sender = "src.email@gmail.com";
        String senderXoauthToken = "R0VUIGh0dHBzOi8vbWFpbC5nb29nbGUuY29tL21haWwvYi9yZWxheW1lLnRpbnl3ZWJnZWFyc0BnbWFpbC5jb20vc210cC8gb2F1dGhfc2lnbmF0dXJlPSJIekpxMFlVdGlwZ3FVTHk3bWVqcCUyRktJYlg3OCUzRCIsc2NvcGU9Imh0dHBzJTNBJTJGJTJGd3d3Lmdvb2dsZWFwaXMuY29tJTJGYXV0aCUyRnVzZXJpbmZvLmVtYWlsJTIwaHR0cHMlM0ElMkYlMkZtYWlsLmdvb2dsZS5jb20lMkYiLG9hdXRoX3ZlcnNpb249IjEuMCIsb2F1dGhfbm9uY2U9IjgzODI2MDUzNyIsb2F1dGhfc2lnbmF0dXJlX21ldGhvZD0iSE1BQy1TSEExIixvYXV0aF9jb25zdW1lcl9rZXk9InJlbGF5bWUudGlueXdlYmdlYXJzLmNvbSIsb2F1dGhfdG9rZW49IjElMkZHVDA0QmxaOWVwYjk1WE10QURSSjNsNEd6b1R4YTJlR3BlYmxvZXRpT0ZvIixvYXV0aF90aW1lc3RhbXA9IjEzNDQ3NDI2MTki";
        String recipient = "destination.email@gmail.com";
        String subject = "Testing Commons Net";
        String body = "Testing at " + new Date();
        String server = "smtp.gmail.com";
        Integer port = 587;

        try
        {
            SimpleSMTPHeader header = new SimpleSMTPHeader(sender, recipient, subject);

            AuthenticatingSMTPClient client = new AuthenticatingSMTPClient();
            client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));
            client.connect(server, port);
            client.login();
            client.execTLS();
            client.auth(AuthenticatingSMTPClient.AUTH_METHOD.XOAUTH, senderXoauthToken, null);

            if (!SMTPReply.isPositiveCompletion(client.getReplyCode()))
            {
                client.disconnect();
                System.err.println("SMTP server refused connection.");
                System.exit(1);
            }

            client.setSender(sender);
            client.addRecipient(recipient);

            Writer writer = client.sendMessageData();
            if (writer != null)
            {
                writer.write(header.toString());
                writer.write(body);
                writer.close();
                client.completePendingCommand();
            }

            client.logout();

            client.disconnect();
        }
        catch (Exception e)
        {
            e.printStackTrace();
            System.exit(1);
        }
    }
}
                
> Support XOAUTH
> --------------
>
>                 Key: NET-482
>                 URL: https://issues.apache.org/jira/browse/NET-482
>             Project: Commons Net
>          Issue Type: Improvement
>          Components: SMTP
>    Affects Versions: 3.1
>            Reporter: Houman Atashbar
>            Priority: Minor
>         Attachments: commons-net-trunk-patch.txt
>
>
> It would be nice if commons-net supported XOAUTH for authentication.
> I could modify the code slightly to get this working, but I thought maybe there is a better way.
> If not, please have a look at my patch and see if it is worthwhile adding it to trunk.
> Thanks

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira