Im tring to send a simple email with this code using google app engine. But nothing happens, is there something i have to configure in order to use the mail api? This runs on localhost. I am using gmail as mail host.
String host = "smtp.google.com";
String to = "[email protected]";
String from = "[email protected]";
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);
The mail API provides two ways to send an email message: the mail. send_mail() function and the EmailMessage class. This page describes how to use the legacy bundled services and APIs. This API can only run in first-generation runtimes in the App Engine standard environment.
To send email from GCP, you first need to create an account. Once you have an account, you can create an email address and set up your GCP account to use that address for email. You can also use your GCP account to access your email messages in the Gmail web interface or through the Google Cloud Platform Console.
An email API (application programming interface) gives applications access to the functionality available in an email platform, such as generating and sending transactional emails, manipulating templates, and enabling access to email metrics.
When running the AppEngine development server locally, anything sent via the Mail service will not actually be sent - it will just be logged to the console
See here
When an application running in the development server calls the Mail service to send an email message, the message is printed to the log. The Java development server does not send the email message.
In addition, the from
address must be (from here)
The sender should be your own Gmail email address instead of [email protected]
Reason is because the SMTP server needs to authenticate you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With