Send mail from Java and camel without turning on less secure app

Viewed 22

I have used this code using camel. Can some code be written to send mail without enabling less secure apps. What are the ways of sending mail without enabling less secure apps.

public class SendMail {

public static void main(String args[]) throws Exception {

    CamelContext context = new DefaultCamelContext();
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() {
        
            
            from("direct:start")
            .to("smtp://smtp.gmail.com:587?username=XYZ@gmail.com&password=Password&from=ABC@gmail.com&contentType=text/html&mail.smtp.starttls.enable=true&mail.smtp.auth=true")
            .log("Email sent");

        }
    });

    context.start();
    
    Endpoint endpoint = context.getEndpoint("direct:start");
    
    Exchange exchange = endpoint.createExchange();
    Message in = exchange.getIn();
    in.setHeader("subject", "Camel logo updated !");
    in.setHeader("to", "ABC@gmail.com");
    in.setHeader("from", "XYZ@gmail.com");
    in.setBody("Logo is in attachment");
    

    Producer producer = endpoint.createProducer();
    producer.start();
    producer.process(exchange);
    
    context.stop();
}

}

0 Answers
Related