Trying to send smtp messages with gen_smtp (plugin), channel.basicPublish (java)

158 views
Skip to first unread message

Mäū Cárdenas

unread,
Mar 2, 2015, 4:53:02 PM3/2/15
to rabbitm...@googlegroups.com
Dear all

My RabbitMQ Server is already set but when I use this command to send smtp messages it doesn't work and I don't receive any error on the compiling, what can I do?

import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;


public class SendEmail {


   
private static String hostname = "127.0.0.1";

   
private static String username = "trabbit";

   
private static String password = "password";

   
private static String vhost = "/";

   
private static String outbox = "outbound_test: Windows Client";

   
private static Integer port = 5672;



   
public static void main(String[] argv) throws Exception {


         
ConnectionFactory factory = new ConnectionFactory();

        factory
.setHost(hostname);

        factory
.setUsername(username);

        factory
.setPassword(password);

        factory
.setVirtualHost(vhost);

        factory
.setPort(port);



       
Connection connection = factory.newConnection();

       
Channel channel = connection.createChannel();

        channel
.queueDeclare(outbox, true, false, false, null);

       
String message = "gen_smtp_client:send({\"what...@test.com\", [\"and...@hijacked.us\"],\n" +
               
" \"Subject: testing\\r\\nFrom: Andrew Thompson \\r\\nTo: Some Dude \\r\\n\\r\\nThis is the email body\"},\n" +
               
"  [{relay, \"smtp.gmail.com\"}, {username, \"user...@gmail.com\"}, {password, \"password\"}])";

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

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

       
// close the channel
        channel
.close();

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

Michael Klishin

unread,
Mar 2, 2015, 4:58:07 PM3/2/15
to rabbitm...@googlegroups.com, Mäū Cárdenas
 On 3 March 2015 at 00:53:05, Mäū Cárdenas (mjc...@gmail.com) wrote:
> My RabbitMQ Server is already set but when I use this command
> to send smtp messages it doesn't work and I don't receive any error
> on the compiling, what can I do?

Please start by being more specific than "it does not work". Checking logs is another
good idea.
--
MK

Staff Software Engineer, Pivotal/RabbitMQ

petr.g...@centrum.cz

unread,
Mar 2, 2015, 5:12:01 PM3/2/15
to rabbitm...@googlegroups.com, mjc...@gmail.com
Location of the log files is described here: https://www.rabbitmq.com/relocate.html

However, when publishing to a queue (using the default exchange) you should provide a queue name as a parameter. I believe the following line is incorrect:

>> channel.basicPublish("", "", null, message.getBytes());

Have a look at the "nameless exchange" here: https://www.rabbitmq.com/tutorials/tutorial-three-java.html


Petr

Simon MacMullen

unread,
Mar 3, 2015, 4:16:47 AM3/3/15
to Mäū Cárdenas, rabbitm...@googlegroups.com
On 02/03/2015 21:53, Mäū Cárdenas wrote:
> |Stringmessage ="gen_smtp_client:send({\"what...@test.com\",
> [\"and...@hijacked.us\"],\n"+
> " \"Subject: testing\\r\\nFrom: Andrew Thompson \\r\\nTo: Some Dude
> \\r\\n\\r\\nThis is the email body\"},\n"+
> " [{relay, \"smtp.gmail.com\"}, {username, \"user...@gmail.com\"},
> {password, \"password\"}])";
> |

This appears to be Erlang example code (or configuration?) copied and
pasted into the message body - that's not how the rabbitmq-email plugin
works, as far as I can see. The config needs to go in your
rabbitmq.config file.

Cheers, Simon

Mäū Cárdenas

unread,
Mar 3, 2015, 9:22:39 AM3/3/15
to rabbitm...@googlegroups.com, mjc...@gmail.com
I don't receive any error message and the Logs doesn't show any remarkable related issue, but my problem is that the email is not being send it through the RabbitMQ Server, also I noticed that in the Rabbit monitor I doesn't have any listening port gem_smtp  2525.

Mäū Cárdenas

unread,
Mar 3, 2015, 9:33:06 AM3/3/15
to rabbitm...@googlegroups.com, mjc...@gmail.com
Dear Simon 

That code was taken from the client example of https://github.com/Vagabond/gen_smtp, I set the rabbitmq.config with this code:

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


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

And for the channel.basicPublish 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\" }";




On Tuesday, March 3, 2015 at 5:16:47 AM UTC-4, Simon MacMullen wrote:
On 02/03/2015 21:53, Mäū Cárdenas wrote:
> |Stringmessage ="gen_smtp_client:send({\"whatev...@test.com\",

Michael Klishin

unread,
Mar 3, 2015, 9:42:34 AM3/3/15
to rabbitm...@googlegroups.com, Mäū Cárdenas
 On 3 March 2015 at 17:33:07, Mäū Cárdenas (mjc...@gmail.com) wrote:
> I set the rabbitmq.config with this code

Which suggests the config is not picked up.

 * Is the config file at the correct location? Log file and management UI should mention effective log file path.
 * Was the plugin enabled? 

Mäū Cárdenas

unread,
Mar 3, 2015, 9:50:40 AM3/3/15
to rabbitm...@googlegroups.com, mjc...@gmail.com
Dear Michael

The config file is located in /etc/rabbitmq/rabbitmq.config, and is running. The Plugin "gen_smtp" has been set on the Plugin directory /usr/lib/rabbitmq/lib/rabbitmq_server-3.4.4/plugins/gen_smtp-0.9.0-rmq0.0.0-gita62c02e.ez.

Status:   * = running on rabbit@MauBuntu
 
|/
[e*] amqp_client                       3.4.4
[  ] cowboy                            0.5.0-rmq3.4.4-git4b93c2d
[E*] gen_smtp                          0.9.0-rmq0.0.0-gita62c02e
[e*] mochiweb                          2.7.0-rmq3.4.4-git680dba8
[E*] rabbitmq_amqp1_0                  3.4.4
[  ] rabbitmq_auth_backend_ldap        3.4.4
[  ] rabbitmq_auth_mechanism_ssl       3.4.4
[  ] rabbitmq_consistent_hash_exchange 3.4.4
[  ] rabbitmq_federation               3.4.4
[  ] rabbitmq_federation_management    3.4.4
[E*] rabbitmq_management               3.4.4
[e*] rabbitmq_management_agent         3.4.4
[  ] rabbitmq_management_visualiser    3.4.4
[E*] rabbitmq_mqtt                     3.4.4
[  ] rabbitmq_shovel                   3.4.4
[  ] rabbitmq_shovel_management        3.4.4
[  ] rabbitmq_stomp                    3.4.4
[  ] rabbitmq_test                     3.4.4
[  ] rabbitmq_tracing                  3.4.4
[e*] rabbitmq_web_dispatch             3.4.4
[  ] rabbitmq_web_stomp                3.4.4
[  ] rabbitmq_web_stomp_examples       3.4.4
[  ] sockjs                            0.3.4-rmq3.4.4-git3132eb9
[e*] webmachine                        1.10.3-rmq3.4.4-gite9359c7



Michael Klishin

unread,
Mar 3, 2015, 9:53:10 AM3/3/15
to rabbitm...@googlegroups.com, Mäū Cárdenas
 On 3 March 2015 at 17:50:43, Mäū Cárdenas (mjc...@gmail.com) wrote:
> The config file is located in /etc/rabbitmq/rabbitmq.config,
> and is running. The Plugin "gen_smtp" has been set on the Plugin
> directory /usr/lib/rabbitmq/lib/rabbitmq_server-3.4.4/plugins/gen_smtp-0.9.0-rmq0.0.0-gita62c02e.ez.

gen_smtp is a library that the plugin needs, not the plugin itself.

Mäū Cárdenas

unread,
Mar 3, 2015, 10:01:39 AM3/3/15
to rabbitm...@googlegroups.com, mjc...@gmail.com
Ok so how I can set the Plugin that I need in order to send STMP mail (inbound and outbound)?

I used this repository considering this was the pluging after compiling it (https://github.com/gotthardp/gen_smtp)

Thank you

Michael Klishin

unread,
Mar 3, 2015, 10:03:23 AM3/3/15
to rabbitm...@googlegroups.com, Mäū Cárdenas
 On 3 March 2015 at 18:01:40, Mäū Cárdenas (mjc...@gmail.com) wrote:
> Ok so how I can set the Plugin that I need in order to send STMP mail
> (inbound and outbound)?
>
> I used this repository considering this was the pluging after
> compiling it (https://github.com/gotthardp/gen_smtp)

The plugin is https://github.com/gotthardp/rabbitmq-email.

Mäū Cárdenas

unread,
Mar 3, 2015, 10:17:30 AM3/3/15
to rabbitm...@googlegroups.com, mjc...@gmail.com
Originally I have this issue compiling with make this repository:

lided] generate deps
[elided] fix test deps
sed
-e 's|build/deps.mk|$(DEPS_FILE)|' build/deps.mk > build/deps.mk.tmp && mv build/deps.mk.tmp build/deps.mk
escript
../generate_app src/rabbitmq_email.app.src ebin/rabbitmq_email.app ./src
sed
-n -e 's|^.*{vsn, *"\([^"]*\)".*$|ORIGINAL_VERSION:=\1|p' <ebin/rabbitmq_email.app >build/version.mk
rm
-rf ../rabbitmq-server/dist
make
-C ../rabbitmq-server
make
[1]: Entering directory `/home/mau777/rabbitmq-public-umbrella/rabbitmq-server'
Makefile:403: deps.mk: No such file or directory
xsltproc --novalid --stringparam modulename "`
basename src/rabbit_ctl_usage.erl .erl`" \
  docs/usage.xsl docs/rabbitmqctl.1.xml > src/rabbit_ctl_usage.erl.tmp
/bin/sh: 1: xsltproc: not found
make[1]: *** [src/rabbit_ctl_usage.erl] Error 127

Then someone suggested me using gen_smtp in place of this plugin, how I can generate this plugin because y tried several times in different servers?

Thanks

Gotthard, Petr

unread,
Mar 3, 2015, 10:19:03 AM3/3/15
to Mäū Cárdenas, rabbitm...@googlegroups.com

The main plugin is named “rabbitmq_email” and it needs to be activated as described here:

http://www.rabbitmq.com/plugin-development.html

 

You will not see the SMTP listening port in the “Port and contexts” table because the plugin is not integrated with it. However it will be shown by the standard “netstat” command.

 

 

Petr

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mäū Cárdenas

unread,
Mar 3, 2015, 11:15:03 AM3/3/15
to rabbitm...@googlegroups.com, mjc...@gmail.com, petr.g...@honeywell.com
I tried exactly as the instructions in (http://www.rabbitmq.com/plugin-development.html), also the plugin settins (https://github.com/gotthardp/rabbitmq-email).  I receive this error compiling make

make
../do-package.mk:168: ../rabbitmq-gen-smtp/package.mk: No such file or directory
[elided] generate deps
[elided] fix test deps
sed
-e 's|../coverage/build/deps.mk|$(DEPS_FILE)|' ../coverage/build/deps.mk > ../coverage/build/deps.mk.tmp && mv ../coverage/build/deps.mk.tmp ../coverage/build/deps.mk
[elided] generate deps
[elided] fix test deps
sed
-e 's|../rabbitmq-gen-smtp/build/deps.mk|$(DEPS_FILE)|' ../rabbitmq-gen-smtp/build/deps.mk > ../rabbitmq-gen-smtp/build/deps.mk.tmp && mv ../rabbitmq-gen-smtp/build/deps.mk.tmp ../rabbitmq-gen-smtp/build/deps.mk
make
: *** No rule to make target `../rabbitmq-gen-smtp/package.mk'.  Stop.

What might be the solution instead?

To post to this group, send email to rabbit...@googlegroups.com.

Simon MacMullen

unread,
Mar 3, 2015, 11:27:34 AM3/3/15
to Mäū Cárdenas, rabbitm...@googlegroups.com, petr.g...@honeywell.com
That error is because gen_smtp is not checked out, it needs both to build.

The plugins in question are actually available in binary form here:
http://www.rabbitmq.com/community-plugins.html#protocols

I strongly recommend using binary plugins when possible, compiling them
can be a pain.

Cheers, Simon

On 03/03/15 16:15, Mäū Cárdenas wrote:
> I tried exactly as the instructions in
> (http://www.rabbitmq.com/plugin-development.html), also the plugin
> settins (https://github.com/gotthardp/rabbitmq-email). I receive this
> error compiling *make*
>
> |
> make
> ../do-package.mk:168:../rabbitmq-gen-smtp/package.mk:Nosuch file ordirectory
> [elided]generate deps
> [elided]fix test deps
> sed -e
> 's|../coverage/build/deps.mk|$(DEPS_FILE)|'../coverage/build/deps.mk
> >../coverage/build/deps.mk.tmp &&mv ../coverage/build/deps.mk.tmp
> ../coverage/build/deps.mk
> [elided]generate deps
> [elided]fix test deps
> sed -e
> 's|../rabbitmq-gen-smtp/build/deps.mk|$(DEPS_FILE)|'../rabbitmq-gen-smtp/build/deps.mk
> >../rabbitmq-gen-smtp/build/deps.mk.tmp &&mv
> ../rabbitmq-gen-smtp/build/deps.mk.tmp ../rabbitmq-gen-smtp/build/deps.mk
> make:***Norule to make target `../rabbitmq-gen-smtp/package.mk'. Stop.
> |
>
> What might be the solution instead?
>
> On Tuesday, March 3, 2015 at 11:19:03 AM UTC-4, Gotthard, Petr wrote:
>
> The main plugin is named “rabbitmq_email” and it needs to be
> activated as described here:
>
> http://www.rabbitmq.com/plugin-development.html
> <http://www.rabbitmq.com/plugin-development.html>
>
> You will not see the SMTP listening port in the “Port and contexts”
> table because the plugin is not integrated with it. However it will
> be shown by the standard “netstat” command.
>
> Petr
>
> *From:*rabbitm...@googlegroups.com <javascript:>
> [mailto:rabbitm...@googlegroups.com <javascript:>] *On Behalf Of
> *Mäu Cárdenas
> *Sent:* 3. března 2015 16:02
> *To:* rabbitm...@googlegroups.com <javascript:>
> *Cc:* mjc...@gmail.com <javascript:>
> *Subject:* Re: [rabbitmq-users] Trying to send smtp messages with
> gen_smtp (plugin), channel.basicPublish (java)
>
> Ok so how I can set the Plugin that I need in order to send STMP
> mail (inbound and outbound)?
>
> I used this repository considering this was the pluging after
> compiling it (https://github.com/gotthardp/gen_smtp
> <https://github.com/gotthardp/gen_smtp>)
>
> Thank you
>
> On Tuesday, March 3, 2015 at 10:53:10 AM UTC-4, Michael Klishin wrote:
>
> On 3 March 2015 at 17:50:43, Mäū Cárdenas (mjc...@gmail.com) wrote:
> > The config file is located in /etc/rabbitmq/rabbitmq.config,
> > and is running. The Plugin "gen_smtp" has been set on the Plugin
> > directory
> /usr/lib/rabbitmq/lib/rabbitmq_server-3.4.4/plugins/gen_smtp-0.9.0-rmq0.0.0-gita62c02e.ez.
>
>
> gen_smtp is a library that the plugin needs, not the plugin itself.
> --
> MK
>
> Staff Software Engineer, Pivotal/RabbitMQ
>
> --
> You received this message because you are subscribed to the Google
> Groups "rabbitmq-users" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to rabbitmq-user...@googlegroups.com <javascript:>.
> To post to this group, send email to rabbit...@googlegroups.com
> <javascript:>.
> For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "rabbitmq-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to rabbitmq-user...@googlegroups.com
> <mailto:rabbitmq-user...@googlegroups.com>.
> To post to this group, send email to rabbitm...@googlegroups.com
> <mailto:rabbitm...@googlegroups.com>.

Gotthard, Petr

unread,
Mar 3, 2015, 11:33:45 AM3/3/15
to Simon MacMullen, Mäū Cárdenas, rabbitm...@googlegroups.com
Yes, using the pre-compiled binaries is preferred.

When building your own plugin you need to download the gen_smtp Integration package from
https://github.com/gotthardp/rabbitmq-gen-smtp


Petr
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send an email to rabbitm...@googlegroups.com.

Mäū Cárdenas

unread,
Mar 3, 2015, 2:10:13 PM3/3/15
to rabbitm...@googlegroups.com, si...@rabbitmq.com, mjc...@gmail.com, petr.g...@honeywell.com
Thank you very much Gotthard,

But I have another issue with the plugins

sudo rabbitmq-plugins enable rabbitmq_email
The following plugins have been enabled:
  gen_smtp
  rabbitmq_email

Applying plugin configuration to rabbit@MauBuntu... failed.
Error: {"no such file or directory","rabbitmq_email.app"}

Now I can't start RabbitMQ Server because of the rabbitmq_email.app file in directory

Michael Klishin

unread,
Mar 3, 2015, 2:11:52 PM3/3/15
to rabbitm...@googlegroups.com, Mäū Cárdenas, petr.g...@honeywell.com
 On 3 March 2015 at 22:10:16, Mäū Cárdenas (mjc...@gmail.com) wrote:
> sudo rabbitmq-plugins enable rabbitmq_email
> The following plugins have been enabled:
> gen_smtp
> rabbitmq_email
>
> Applying plugin configuration to rabbit@MauBuntu... failed.
> Error: {"no such file or directory","rabbitmq_email.app"}
>
> Now I can't start RabbitMQ Server because of the rabbitmq_email.app
> file in directory

rabbitmq-plugins disable rabbitmq_email --offline should help.

Mäū Cárdenas

unread,
Mar 3, 2015, 2:21:29 PM3/3/15
to rabbitm...@googlegroups.com, mjc...@gmail.com, petr.g...@honeywell.com
Thank you Michael, 

Perfect the server is working again, but I still can't run rabbitmq_smtp first because I have error trying to compiling it, second the binary file presents this issue with the absent file. What would be the best solution?

Michael Klishin

unread,
Mar 3, 2015, 3:29:10 PM3/3/15
to rabbitm...@googlegroups.com, Mäū Cárdenas, petr.g...@honeywell.com
On 3 March 2015 at 22:21:31, Mäū Cárdenas (mjc...@gmail.com) wrote:
> Perfect the server is working again, but I still can't run rabbitmq_smtp
> first because I have error trying to compiling it, second the
> binary file presents this issue with the absent file. What would
> be the best solution?

I'm confused. rabbitmq_smtp? That's a different plugin from rabbitmq_email.

How did you install it? You need to copy the *.ez file(s) of the plugin into the plugins directory and restart
RabbitMQ, then enable the plugin.

W hat *exactly* have you done?

Mäū Cárdenas

unread,
Mar 3, 2015, 3:33:02 PM3/3/15
to rabbitm...@googlegroups.com, mjc...@gmail.com, petr.g...@honeywell.com
Sorry Michael,

I meant rabbitmq_email 

When I install the binary plugin I have this error:

sudo rabbitmq-plugins enable rabbitmq_email
The following plugins have been enabled:
  gen_smtp
  rabbitmq_email

Applying plugin configuration to rabbit@MauBuntu... failed.
Error: {"no such file or directory","rabbitmq_email.app"}

Also I have problems compiling the rabbitmq_email, that wouldn't allow me many options to use this plugin.
Reply all
Reply to author
Forward
0 new messages