Sending email using the Google engine

Im tring to send a simple email with this code using the google engine. But nothing happens, is there something I need to configure in order to use api mail? This works on localhost. I use gmail as a mail host.

   String host = "smtp.google.com";
String to = "example@yahoo.fr";
String from = "example@gmail.com";
String subject = "this is a test";
String messageText = "test";
boolean sessionDebug = false;
// Create some properties and get the default Session.
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");
Session mailSession = Session.getDefaultInstance(props, null);

// Set debug on the Session
// Passing false will not echo debug info, and passing True will.

mailSession.setDebug(sessionDebug);

// Instantiate a new MimeMessage and fill it with the 
// required information.

Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = { new InternetAddress(to) };
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);

// Hand the message to the default transport service
// for delivery.

Transport.send(msg);
+5
source share
4 answers

When you start the AppEngine development server locally, all messages sent through the Mail service will not actually be sent - it will simply be registered on the console

Look here

, , , . Java .

, from ( )

  • , , Google
+9

Gmail example@gmail.com

, SMTP- .

+1

-, GAE . : project-id@appspot.gserviceaccount.com

, - admin.

+1
source

Besides the fact that the e-mail does not work on localhost or because the sender address is not authenticated, I came across the fact that the e-mail does not work, even if the version is not standard. I could not find documented anywhere.

For example: nondefaultversion-dot-myapp.appspot.com(email does not work, no error logs) myapp.appspot.com(email works)

Please acknowledge that others have also encountered this problem.

0
source

All Articles