Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Properties props= new Properties();
- String host= "express-relay.jangosmtp.net";
- Session sessione;
- final String username="";
- String user= "";
- String pass="";
- final String password="";
- Message m;
- String from= "boooomber@gmail.com";
- String to= "";
- String ob="ProvaAllegato";
- String text="ole";
- String file="voucher.pdf";
- public void inviamail( ){
- props.put("mail.smtp.auth", "true");
- props.put("mail.smtp.host", host);
- sessione = Session.getInstance(props, new Authenticator(){
- protected PasswordAuthentication getPasswordAuthentication(){
- return new PasswordAuthentication(username,password);
- }
- });
- try{
- m= new MimeMessage(sessione);
- m.setFrom(new InternetAddress(from));
- m.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
- m.setSubject(this.ob);
- //m.setText(text);
- BodyPart messageB= new MimeBodyPart();
- messageB.setText(text);
- Multipart multipart= new MimeMultipart();
- multipart.addBodyPart(messageB);
- messageB= new MimeBodyPart();
- DataSource source= new FileDataSource(file);
- messageB.setDataHandler(new DataHandler(source));
- messageB.setFileName(file);
- multipart.addBodyPart(messageB);
- m.setContent(multipart);
- //m.setText(text);
- Transport.send(m);
- System.out.println("inviata");
- }catch(Exception e){
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement