RabbitMQ SMTP full connection issues (require a guide for setting up server and client)

294 views
Skip to first unread message

Mäū Cárdenas

unread,
Feb 26, 2015, 3:25:56 PM2/26/15
to rabbitm...@googlegroups.com
Dear All

I'm barely new into Message Queue and I'm trying to make Email queque for a server and client application (inbound | outbound) .

I have installed the RabbitMQ Server with the management plugins, and gen_smtp compiled and installed correctly, but my server didn't had any rabbitmq.config file so I use the doc example (attached to this post) and this settings explained in repository (https://github.com/gotthardp/rabbitmq-email), 

{rabbitmq_email, [
    % gen_smtp server parameters
    % see https://github.com/Vagabond/gen_smtp#server-example
    {server_config, [
        [{port, 2525}, {protocol, tcp}, {domain, "gmail.com"}, {address,{0,0,0,0}}]
    ]},
    % inbound email exchanges: [{email-domain, {vhost, exchange}}, ...}
    {email_domains,
        [{<<"gmail.com">>, {<<"/">>, <<"email-in">>}}
    ]},

    % outbound email queues: [{{vhost, queue}, email-domain}, ...]
    {email_queues,
        [{{<<"/">>, <<"email-out">>}, <<"gmail.com">>}
    ]},
    % sender indicated in the From header
    {client_sender, "nor...@gmail.com"},
    % gen_smtp client parameters
    % see https://github.com/Vagabond/gen_smtp#client-example
    {client_config, [
        {relay, "smtp.gmail.com"}
    ]}
]}

My mail server has Postfix using my gmail acount and is working.

This is my java code for sending:

public class SendEmail {

    // same as the rabbitmq-host option in the config file
    private static String hostname = "localhost";

    // same as the rabbitmq-user option in the config file
    private static String username = "guest";

    // same as the rabbitmq-password option in the config file
    private static String password = "guest";

    // same as the rabbitmq-vhost option in the config file
    private static String vhost = "/";

    // same as the rabbitmq-outbox option in the config file
    private static String outbox = "outbound_test: Mauricio";

    // same as the rabbitmq-port option in the config file
    private static Integer port = 5672;

    // domain where the test message should be delivered
    private static String recipientDomain = "gmail.com";

    // email where the test message should be delivered
    private static String recipientEmail = "clien...@gmail.com";

    // address where the email was sent from
    private static String fromAddress = "admin...@gmail.com";

    /**
     *  Main method
     */
    public static void main(String[] argv) throws Exception {
        // create a new ConnectionFactory
        ConnectionFactory factory = new ConnectionFactory();

        // set the host to RabbitMQ
        factory.setHost(hostname);

        // set the user name to connect to RabbitMQ
        factory.setUsername(username);

        // set the password to connect to RabbitMQ
        factory.setPassword(password);

        // set the virtual host to RabbitMQ
        factory.setVirtualHost(vhost);

        // set the port to connect RabbitMQ
        factory.setPort(port);

        // create the new connection
        Connection connection = factory.newConnection();

        // create the channel
        Channel channel = connection.createChannel();

        // declare the queue
        channel.queueDeclare(outbox, true, false, false, null);

        // create the message
        String message = "{ \"envelope\": \"" + fromAddress + "\", "
                + "\"recipient\": \"" + recipientEmail + "\", "
                + "\"body\": \"" + "From: " + fromAddress + "\r\nTo: "
                + recipientEmail
                + "\r\nSubject: Example subject\r\n\r\n"
                + "This is the example message text\" }";

        // publish the message on the queue
        channel.basicPublish("exchange1", "key1", null, message.getBytes());

        // some output
        System.out.println("Sent: '" + message + "'");

        // close the channel
        channel.close();

        // close the connection
        connection.close();
    }
}

I truly doesn't know what I'm doing wrong but I cant make any test with this code that apparently is correct (locally and remotely), also when I use a client-computer (using other IP 10.100.0.39:5672) mi connection is refused for all kind of tests.

Any help would be amazing, thank you so much
rabbitmq_config_example.txt

Michael Klishin

unread,
Feb 26, 2015, 11:30:11 PM2/26/15
to rabbitm...@googlegroups.com, Mäū Cárdenas
 On 26 February 2015 at 23:25:58, Mäū Cárdenas (mjc...@gmail.com) wrote:
> I truly doesn't know what I'm doing wrong but I cant make any test
> with this code that apparently is correct (locally and remotely),
> also when I use a client-computer (using other IP 10.100.0.39:5672)
> mi connection is refused for all kind of tests.

You connect with default credentials. The default user, guest/guest, can only connect
from localhost. Allowing otherwise is asking for security issues.

This is mentioned on http://www.rabbitmq.com/access-control.html and in the installation
guides.

In the future, please provide stack traces when asking questions. 
--
MK

Staff Software Engineer, Pivotal/RabbitMQ

Mäū Cárdenas

unread,
Feb 27, 2015, 10:24:13 AM2/27/15
to rabbitm...@googlegroups.com, mjc...@gmail.com
Alright it connects to the RabbitMQ Server thank you, but when I run the code I receive this error and I'm not sure what is wrong. MAybe I need to set something in the rabbitmq.config file?

Stack Trace:
Exception in thread "main" com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'exchange' in vhost '/', class-id=60, method-id=40)
 at com
.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)
 at com
.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:37)
 at com
.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:354)
 at com
.rabbitmq.client.impl.ChannelN.close(ChannelN.java:573)
 at com
.rabbitmq.client.impl.ChannelN.close(ChannelN.java:505)
 at com
.rabbitmq.client.impl.ChannelN.close(ChannelN.java:498)
 at
SendEmail.main(SendEmail.java:84)
 at sun
.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun
.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java
.lang.reflect.Method.invoke(Method.java:483)
 at com
.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'exchange' in vhost '/', class-id=60, method-id=40)
 at com
.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:478)
 at com
.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:315)
 at com
.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:144)
 at com
.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:91)
 at com
.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:552)
 at java
.lang.Thread.run(Thread.java:745)

This happens when I set Exchange in the publication line:
channel.basicPublish("exchange", "key1", null, message.getBytes());

My actual rabbitmq.config file using gen_smtp:

[
 
{rabbit,
 
[
   
{tcp_listeners, [5672]},
   
{default_vhost,       <<"/">>},
   
{default_user,        <<"guest">>},
   
{default_pass,        <<"guest">>},
   
{default_permissions, [<<".*">>, <<".*">>, <<".*">>]}


 
]},


 
{rabbitmq_email, [

     
{server_config, [
         
[{port, 2525}, {protocol, tcp}, {domain, "gmail.com"}, {address,{0,0,0,0}}]
     
]},

     
{email_domains,
         
[{<<"gmail.com">>, {<<"/">>, <<"email-in">>}}
     
]},

     
{email_queues,
         
[{{<<"/">>, <<"email-out">>}, <<"gmail.com">>}
     
]},

     
{client_sender, "nor...@gmail.com"},
     
{client_config, [
         
{relay, "smtp.gmail.com"}
     
]}
 
]}
].

Michael Klishin

unread,
Feb 27, 2015, 10:29:45 AM2/27/15
to rabbitm...@googlegroups.com, Mäū Cárdenas
On 27 February 2015 at 18:24:15, Mäū Cárdenas (mjc...@gmail.com) wrote:
> This happens when I set Exchange in the publication line:
> channel.basicPublish("exchange", "key1", null, message.getBytes());

The error message is pretty to the point: the exchange "exchange" does not exist.
Reply all
Reply to author
Forward
0 new messages