Thursday, 11 March 2021

Send email with attachment in spring boot

 https://howtodoinjava.com/spring-boot2/send-email-with-attachment/

public void sendMailWithAttachment(String to, String subject, String bodyTextMsg, String fileToAttach) 

{

System.out.println("file loc------------"+fileToAttach);

    MimeMessagePreparator preparator = new MimeMessagePreparator() 

    {

        public void prepare(MimeMessage mimeMessage) throws Exception 

        {

            mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(to));

            mimeMessage.setFrom(new InternetAddress(fromEmailId));

            mimeMessage.setSubject(subject);

            

            Multipart multipartContent= new MimeMultipart();

            MimeBodyPart mimeBodyPart =new MimeBodyPart();

            mimeBodyPart.setText(bodyTextMsg);

            MimeBodyPart mimeBodyPartAttachment =new MimeBodyPart();

            mimeBodyPartAttachment.attachFile(fileToAttach);

            multipartContent.addBodyPart(mimeBodyPart);

            multipartContent.addBodyPart(mimeBodyPartAttachment);

            mimeMessage.setContent(multipartContent,"text/csv; charset=utf-8");

            System.out.println("email send sucessfully");

        }

    };

     

    try {

        mailSender.send(preparator);

        System.out.println("email send sucessfully");

        

    }

    catch (MailException ex) {

        // simply log it and go on...

        System.out.println(ex.getMessage());

    }

}


https://coderanch.com/t/271609/java/Java-Mail-send-Multiple-recipients

Monday, 8 March 2021

Read only collection

 https://javarevisited.blogspot.com/2012/07/create-read-only-list-map-set-example-java.html#axzz6obBnjvcF

Monday, 1 March 2021

Generate and Load SSH Keys into SourceTree with PuTTY

 https://confluence.atlassian.com/sourcetreekb/generate-and-load-ssh-keys-into-sourcetree-with-putty-790629663.html

Tuesday, 23 February 2021

Is Node.js Really Single-Threaded?

 https://betterprogramming.pub/is-node-js-really-single-threaded-7ea59bcc8d64

Monday, 22 February 2021

PM2 setup on production

 https://www.tecmint.com/install-pm2-to-run-nodejs-apps-on-linux-server/


https://www.digitalocean.com/community/tutorials/how-to-use-pm2-to-setup-a-node-js-production-environment-on-an-ubuntu-vps

Thursday, 4 February 2021

Integer to comma separated string

ShopCategoryIds.stream().map(String::valueOf)

        .collect(Collectors.joining(","));

Wednesday, 27 January 2021

Best practice for passing many arguments to method?

Pass a object that hold you parameters then pass that object to function.


Avoid longlist parameters  use Object or array of parameters

Advantage

 Consider you used longlist function on three place and you want to add more 1 then in this case you need to modify code at three places .

If you use object or array then once place change is required.



https://stackoverflow.com/questions/2432443/best-practice-for-passing-many-arguments-to-method


https://stackoverflow.com/questions/36904955/passing-single-object-vs-passing-multiple-parameters