开发者

anonymously send an email from javamail

开发者 https://www.devze.com 2023-01-25 00:57 出处:网络
I have an application that reads emails from ONE email account (gmail application account) but this account has many aliases x@domain.com y@domain.com and x@domain.com they all email MAIN@domain.com

I have an application that reads emails from ONE email account (gmail application account) but this account has many aliases x@domain.com y@domain.com and x@domain.com they all email MAIN@domain.com

I have set up a java application to read mails from MAIN@domain.com 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 MAIN开发者_开发知识库@domain.com

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消