Reputation: 11
I have an application that reads emails from ONE email account (gmail application account) but this account has many aliases [email protected] [email protected] and [email protected] they all email [email protected]
I have set up a java application to read mails from [email protected] but depending on the alias it should reply to the email from the alias and not show the main email everything is being forwarded to.
everytime I test it ignores the from alias and just sends from [email protected]
how can I change this ?!
the code
String SMTP_HOST_NAME = "smtp.gmail.com";
Properties props = new Properties();
props.put("mail.smtps.host", SMTP_HOST_NAME);
props.put("mail.smtps.auth", "false");
Session mailSession = Session.getInstance(props);
try {
MimeMessage message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress(AliasEmail));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(email + carrier));
message.setSubject(FileUtils.readFileToString(new File(Alias
+ "-confirm-subject.txt")));
message.setText(FileUtils.readFileToString(new File(Alias + "-confirm.txt")),
"text/plain");
message.setContent(FileUtils.readFileToString(new File(Alias + "-confirm.html")),
"text/html");
Transport transport = mailSession.getTransport("smtps");
transport.connect(SMTP_HOST_NAME, MAINuser, MAINpassword);
transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
transport.close();
logger.info("Email Confirmation Sent = [" + Alias + carrier + "]");
thank you in advance
Upvotes: 0
Views: 5922
Reputation: 2845
It is very likely that Gmail won't let you send e-mail from any address you choose (this is how it is in the normal web interface, so I'd expect that's how it is in the SMTP interfaces as well). You may have no solution but to use another mail server for outgoing e-mails. Registering the alternate addresses as your own in Gmail's settings might work, too.
Upvotes: 2