I have gmail configuration script for send email using Gmail mail service, and these codes can send email Correctly:
public static void sendEmail() throws AddressException, MessagingException {
String emailBody = "This is body of message xxx";
mailServerProperties = System.getProperties();
mailServerProperties.put("mail.smtp.port", "587");
mailServerProperties.put("mail.smtp.auth", "true");
mailServerProperties.put("mail.smtp.starttls.enable", "true");
getMailSession = Session.getDefaultInstance(mailServerProperties, null);
generateMailMessage = new MimeMessage(getMailSession);
generateMailMessage.addRecipient(Message.RecipientType.CC, new InternetAddress(receiveremail#gmail.com));
generateMailMessage.setSubject("This is subject xxx");
generateMailMessage.setContent(emailBody, "text/html");
Transport transport = getMailSession.getTransport("smtp");
transport.connect("smtp.gmail.com", "my-email#gmail.com", "mypasswordxxx");
transport.sendMessage(generateMailMessage, generateMailMessage.getAllRecipients());
transport.close();
}
Then I want to use Zimbra mail service with my own mail domain (findtaxi.com).
I want send email using my email domain (justin#findtaxi.com), it use Zimbra service. I follow this configuration, I change some values :
mailServerProperties.put("mail.smtp.port", "25");
transport.connect("zimbra.findtaxi.com", "justin#findtaxi.com", "thispassword");
But cannot send the message.
javax.mail.MessagingException: Could not connect to SMTP host: zimbra.findtaxi.com, port: 25; nested exception is:
java.net.ConnectException: Connection timed out: connect
Is it possible to send email with Zimbra on javamail?
Related
I am trying to send message from java using aws SES .I saw similar question but I tried all the answers from that.
Question link: Amazon SES 535 Authentication Credentials Invalid
I have domain in SES management and created there from SMTP setting new IAM user with SMTP credentials, tried to login but giving this Error message: 535 Authentication Credentials Invalid.
Here is code:
static final String FROM = "news#example"; //have verified email
static final String FROMNAME = "NAME";
// Replace recipient#example.com with a "To" address. If your account
// is still in the sandbox, this address must be verified.
static final String TO = "my#gmail.com";
// Replace smtp_username with your Amazon SES SMTP user name.
static final String SMTP_USERNAME = "AKIAQZG5ZQZURE****";
// Replace smtp_password with your Amazon SES SMTP password.
static final String SMTP_PASSWORD = "MNYYlLz5sBB%2FA8****";//even encoded
// The name of the Configuration Set to use for this message.
// If you comment out or remove this variable, you will also need to
// comment out or remove the header below.
// static final String CONFIGSET = "ConfigSet";
// Amazon SES SMTP host name. This example uses the US West (Oregon) region.
// See https://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html#region-endpoints
// for more information.
static final String HOST = "email-smtp.eu-west-1.amazonaws.com";
// The port you will connect to on the Amazon SES SMTP endpoint.
static final int PORT = 25;
static final String SUBJECT = "Amazon SES test (SMTP interface accessed using Java)";
static final String BODY = String.join(
System.getProperty("line.separator"),
"<h1>Amazon SES SMTP Email Test</h1>",
"<p>This email was sent with Amazon SES using the ",
"<a href='https://github.com/javaee/javamail'>Javamail Package</a>",
" for <a href='https://www.java.com'>Java</a>."
);
public static void main(String[] args) throws Exception {
// Create a Properties object to contain connection configuration information.
Properties props = System.getProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.port", PORT);
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
// Create a Session object to represent a mail session with the specified properties.
Session session = Session.getDefaultInstance(props);
// Create a message with the specified information.
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(FROM,FROMNAME));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(TO));
msg.setSubject(SUBJECT);
msg.setContent(BODY,"text/html");
// Add a configuration set header. Comment or delete the
// next line if you are not using a configuration set
// msg.setHeader("X-SES-CONFIGURATION-SET", CONFIGSET);
// Create a transport.
Transport transport = session.getTransport();
// Send the message.
try
{
System.out.println("Sending...");
// Connect to Amazon SES using the SMTP username and password you specified above.
transport.connect(HOST, SMTP_USERNAME, SMTP_PASSWORD);
// Send the email.
transport.sendMessage(msg, msg.getAllRecipients());
System.out.println("Email sent!");
}
catch (Exception ex) {
System.out.println("The email was not sent.");
System.out.println("Error message: " + ex.getMessage());
}
finally
{
// Close and terminate the connection.
transport.close();
}
}
Attached two pictures , first one is IAM permission policy and second is SES domain permission policy
I have been verified both from and to email addresses(both the emails are case sensitive) over and over
and I still get the 554 Message rejected: Email address is not verified Rejection from SES. But when i try to send the emails from Amazon SES Console by using the same email, it is working fine. If my from and to emails not been verified then from console also it should nt work. Not able to understand what is going on.
public class AmazonSESSample {
static final String FROM = "from email";
static final String TO = "to email";
static final String BODY = "This email was sent through the Amazon SES SMTP interface by using Java.";
static final String SUBJECT = "Amazon SES test (SMTP interface accessed using Java)";
// Supply your SMTP credentials below. Note that your SMTP credentials are different from your AWS credentials.
static final String SMTP_USERNAME = "SMTP USER NAME";
static final String SMTP_PASSWORD = "SMTP PWD";
static final String HOST = "email-smtp.us-east-1.amazonaws.com";
// Port we will connect to on the Amazon SES SMTP endpoint. We are choosing port 25 because we will use
// STARTTLS to encrypt the connection.
static final int PORT = 25;
public static void main(String[] args) throws Exception {
// Create a Properties object to contain connection configuration information.
Properties props = System.getProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.port", PORT);
// Set properties indicating that we want to use STARTTLS to encrypt the connection.
// The SMTP session will begin on an unencrypted connection, and then the client
// will issue a STARTTLS command to upgrade to an encrypted connection.
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
// Create a Session object to represent a mail session with the specified properties.
Session session = Session.getDefaultInstance(props);
// Create a message with the specified information.
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(FROM));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(TO));
msg.setSubject(SUBJECT);
msg.setContent(BODY,"text/plain");
// Create a transport.
Transport transport = session.getTransport();
// Send the message.
try
{
System.out.println("Attempting to send an email through the Amazon SES SMTP interface...");
// Connect to Amazon SES using the SMTP username and password you specified above.
transport.connect(HOST, SMTP_USERNAME, SMTP_PASSWORD);
// Send the email.
transport.sendMessage(msg, msg.getAllRecipients());
System.out.println("Email sent!");
}
catch (Exception ex) {
System.out.println("The email was not sent.");
System.out.println("Error message: " + ex.getMessage());
ex.printStackTrace();
}
finally
{
// Close and terminate the connection.
transport.close();
}
}
}
I had the same problem, and it turned out to be a simple blind copy-paste issue. Currently, there are 3 regions with SES. Depending on which region you setup the ID, the HOST variable has to be modified accordingly.
static final String HOST = "email-smtp.us-east-1.amazonaws.com";
That fixed my problem. Afterwards, if you want to send emails to unverified email addresses, you have to move your setup out of the sandbox.
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/request-production-access.html
Is this the first time you are using this account with SES? If so then you must be in sandbox mode
If your account is still in the sandbox, you also must verify every recipient email address except for the recipients provided by the Amazon SES mailbox simulator.
SES Doc
You can follow these steps :
1 Log into the AWS Management Console.
2 Go to SES Sending Limits Increase.
3 Fill in the required details and set the limit to your desired usage
Moving Out of Sandbox
I am using aws smtp for sending mail in java project but when I am running my java project I am getting exception. I copied this program from here http://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-smtp-java.html
But after following same steps as given in this link I am getting this exception so please suggest me what should I do.
Here is my code..
public class AmazonSESSample {
static final String FROM = "ansh#artle.in"; // Replace with your "From" address. This address must be verified.
static final String TO = "amit0133#gmail.com"; // Replace with a "To" address. If your account is still in the
// sandbox, this address must be verified.
static final String BODY = "This email was sent through the Amazon SES SMTP interface by using Java.";
static final String SUBJECT = "Amazon SES test (SMTP interface accessed using Java)";
// Supply your SMTP credentials below. Note that your SMTP credentials are different from your AWS credentials.
static final String SMTP_USERNAME = "My SMTP username"; // Replace with your SMTP username.
static final String SMTP_PASSWORD = " my SMTP password"; // Replace with your SMTP password.
// Amazon SES SMTP host name. This example uses the US West (Oregon) region.
static final String HOST = "email-smtp.us-west-2.amazonaws.com";
// Port we will connect to on the Amazon SES SMTP endpoint. We are choosing port 25 because we will use
// STARTTLS to encrypt the connection.
static final int PORT = 587;
public static void main(String[] args) throws Exception {
// Create a Properties object to contain connection configuration information.
Properties props = System.getProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.port", PORT);
// Set properties indicating that we want to use STARTTLS to encrypt the connection.
// The SMTP session will begin on an unencrypted connection, and then the client
// will issue a STARTTLS command to upgrade to an encrypted connection.
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
// Create a Session object to represent a mail session with the specified properties.
Session session = Session.getDefaultInstance(props);
// Create a message with the specified information.
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(FROM));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(TO));
msg.setSubject(SUBJECT);
msg.setContent(BODY,"text/plain");
// Create a transport.
Transport transport = session.getTransport();
// Send the message.
try
{
System.out.println("Attempting to send an email through the Amazon SES SMTP interface...");
// Connect to Amazon SES using the SMTP username and password you specified above.
transport.connect(HOST, SMTP_USERNAME, SMTP_PASSWORD);
// Send the email.
transport.sendMessage(msg, msg.getAllRecipients());
System.out.println("Email sent!");
}
catch (Exception ex) {
ex.printStackTrace();
System.out.println("The email was not sent.");
System.out.println("Error message: " + ex.getMessage());
}
finally
{
// Close and terminate the connection.
transport.close();
}
}
}
Here is Exception
Attempting to send an email through the Amazon SES SMTP interface...
The email was not sent.
Error message: null
javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:264)
at javax.mail.Service.connect(Service.java:134)
at awssmtp.AmazonSESSample.main(AmazonSESSample.java:60)
I have below code to send an email to my gmail.
public class Mainclass {
public static void main(String args[]){
String host = "smtp.gmail.com";
String from = "from_address#fdsl.com";
String to = "mymail#gmail.com";
// Set properties
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.debug", true);
props.put("mail.smtp.auth", true);
props.put("mail.smtp.starttls.enable", true);
props.put("username", "mymail#gmail.com");
props.put("password", "mypassword");
// Get session
Session session = Session.getInstance(props);
try {
// Instantiate a message
Message msg = new MimeMessage(session);
// Set the FROM message
msg.setFrom(new InternetAddress(from));
// The recipients can be more than one so we use an array but you can
// use 'new InternetAddress(to)' for only one address.
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
// Set the message subject and date we sent it.
msg.setSubject("Email from JavaMail test");
msg.setSentDate(new Date());
// Set message content
msg.setText("This is the text for this simple demo using JavaMail.");
// Send the message
Transport.send(msg);
}
catch (MessagingException mex) {
mex.printStackTrace();
}
}
}
But when i run the code i always get below the exception.
javax.mail.AuthenticationFailedException: failed to connect, no password specified?
at javax.mail.Service.connect(Service.java:329)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at Mainclass.main(Mainclass.java:66)
Am i missing anything here? My password is correct. Please help me.
Thanks!
Have you set the host correctly ? Also, I don't see which ports are you using to connect. Have you set the correct ports? Is TLS the correct auth encryption for gmail ?
Please see the attached config:
'SMTP::TLS',
Host => 'smtp.gmail.com',
Port => 587,
User => 'username#gmail.com',
Password => 'password'
I am building an android app. I want to send an email from xxxxx#outlook.com. This is the code.
public void setUp
{
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
this.mailhost = "smtp.live.com";
props.setProperty("mail.host", mailhost);
props.put("mail.smtp.port", "587");
props.setProperty("mail.smtp.starttls.enable", "true");
}
I know that user should be the whole email address. But when I used I received an email that said I should start session before send a email.
This code worked 3 times and then stopped.
What does the debug output show? What was the exact error message? Exactly what did it say in the email you received? You may need to connect with POP3 or IMAP to read mail before it will let you send mail.
You should get a session from Javamail, to create your message. Then, using a transport object, you can send it.
String host = "localhost";
int port = 443;
String user = "BruceWayne#example.org";
String password = "S3cr3tP4ss";
Session session = Session.getDefaultInstance(props);
session.setDebug(true);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(user, "Dark Knight"));
msg.setSubject("Hello Selina");
msg.setText("Do you want to have diner ?");
Transport transport = session.getTransport("smtp");
transport.connect(host, port, user, password);
transport.sendMessage(msg, msg.getAllRecipients());