piątek, 18 października 2013

How to send mails from JBoss Wildfly (JavaMail & GMail)

It only takes a couple of minutes to configure Wildfly 8.0.0.Alpha4 server to send mails using your Google account.


  1. Turn on standalone WildFly instance

    ./<wild_fly_home>/bin/standalone.sh

  2. Add new Mail Session (assign JNDI name, you would like to use in your applications)



  3. When the session is created, click View and add some necessary properties like your username, password, SSL encryption etc

  4. Save changes and shut down Wildfly server (CTRL+C in terminal)
  5. Open standalone configuration file (<wild_fly_home>/standalone/configuration/standalone.xml) and replace lines:

    <outbound-socket-binding name="mail-smtp">
      <remote-destination host="localhost" port="25"/>
    </outbound-socket-binding>

    with

    <outbound-socket-binding name="mail-smtp">
      <remote-destination host="smtp.gmail.com" port="465"/>
    </outbound-socket-binding>
  6. Start Wildfly (look 1.)

How to send mail from Java EE?

Use this EJB as an example:
import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.logging.Level;
import java.util.logging.Logger;

@Stateless
public class Mail {

    @Resource(name = "java:jboss/mail/gmail")
    private Session session;

    public void send(String addresses, String topic, String textMessage) {

        try {

            Message message = new MimeMessage(session);
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(addresses));
            message.setSubject(topic);
            message.setText(textMessage);

            Transport.send(message);

        } catch (MessagingException e) {
            Logger.getLogger(Mail.class.getName()).log(Level.WARNING, "Cannot send mail", e);
        }
    }
}

Keep it simple!

środa, 9 października 2013

How not to get cheated in Morocco?

Morocco is considered as the most civilized African country. The difference between other continents though is still huge. People are mostly poor, and try to earn as much money as they can from tourists. Prices are different for every customers. If traders spot that you come from rich country (i.e. Germany or France) or wear good clothes they will ask you for more money.

When buying something the most important think to remember it to negotiate prices. Moroccans will often check you by asking if it is your first time in Morocco. Even if it is, you should always answer negative. You have been here a year ago, and you also have family in Casablanca. They won't be so confident after this.

I remember when we were buying some souvenirs (local women dress) and asked for the price. First we heard 2000 MAD (about 180 EUR). The best thing you can do in such situation is just start to leave the place. Traders will start pulling your sleeves, and dropping prices - in our case to 150 MAD (14 EUR) without saying any word.

They are awfully good at marketing techniques. Remember not to take anything from them without hearing the price first. You will hear many things like that is a gift, just try it on (clothes) or price later. There is really much harder to deal with them later, so avoid such situations and make simple and clear rules at the beginning (also difficult because they talk a lot).

Forget about buses when you are in bigger city. The main way to travel is by taxis. There are two sorts of those: petite taxi, and grande taxis. They look like parts from different car vendors were mixed together and created one car (I don't know why but it never crashed).

There are two ways to deal with taxi drivers.
  • determine the price before entering the vehicle.
  • making sure that kilometers counter is set correctly, don' talk about the money and pay the price that is displayed (the cheapest way).

Don't get caught in arguments like "higher night hacks", or "far away". Just start to walk away, and you will make the satisfying agreement.