0

ここでは完全に正常に動作しますが、受信したファイルを使用する代わりにファイルパスを使用しています入力ストリームに変換するとうまくいきますが、入力ストリームを持つコンストラクターはありません事前にお知らせくださいありがとう

@RequestMapping("/SendMail")
    public String mail(@RequestParam("prescription") MultipartFile prescription,@RequestParam("email") String email,HttpSession session) {
        try {
            customer ct=custServ.customerExists(email);
            InputStream in = prescription.getInputStream();
            String filename=prescription.getName();
            if(ct!=null){
                final String SEmail="email@gmail.com";
                final String SPass="passowrd";
                final String REmail=email;
                final String Sub="Your prescription is here!";
                //mail send Code
            Properties props=new Properties();
            props.put("mail.smtp.host","smtp.gmail.com");
            props.put("mail.smtp.socketFactory.port","465");
            props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
            props.put("mail.smtp.auth","true");
            props.put("mail.smtp.port","465");
            Session ses=Session.getInstance(props,
            new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication(){
                    return new PasswordAuthentication(SEmail,SPass);
                }
            }
            );
            Message message=new MimeMessage(ses);
            message.setFrom(new InternetAddress(SEmail));
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(REmail));
            message.setSubject(Sub);
            
            BodyPart messageBodyPart = new MimeBodyPart();
             messageBodyPart.setText("This is your prescription here");
             Multipart multipart = new MimeMultipart();
            multipart.addBodyPart(messageBodyPart);
            messageBodyPart = new MimeBodyPart(); 
            
           // File filep=new File(prescription);
            DataSource source = new FileDataSource("C:\\Users\\Narci\\Desktop\\frontend\\Myqr3.jpg");
            messageBodyPart.setDataHandler(new DataHandler(source));
            messageBodyPart.setFileName(filename);
            multipart.addBodyPart(messageBodyPart);
             message.setContent(multipart);
            
            Transport.send(message);
            session.setAttribute("msg","Mail Sent successfully.");
            }
            else{
                session.setAttribute("msg", "Wrong Emial ID");
            }
            return "Doctor";
        }
        catch(Exception e) {
        e.printStackTrace();
        return "Error";
        }
    } ```

4

2 に答える 2