I'm barely new into Message Queue and I'm trying to make Email queque for a server and client application (inbound | outbound) .
{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.
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
// address where the email was sent from
/**
* 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();
}
}