Ajouter un commentaire

salim81
pb serveur smtp

mon bout de code:

public void SenderMail(){
		System.setProperty("javax.net.debug", "all");
		String protocol = "SMTPS";
		String socketFactory = "javax.net.ssl.SSLSocketFactory";
		String smtpAuth = "true";
		Properties props = new Properties();
				props.put("mail.transport.protocol", protocol);
				props.put("mail.SMTPS.port", "25");
				props.put("mail.SMTPS.starttls.enable","true");
				props.put("mail.SMTPS.auth", smtpAuth);
				props.put("mail.SMTPS.socketFactory.class", socketFactory);
				props.put("mail.SMTPS.socketFactory.port", "25");
				
//		 Creating mail session
				session = Session.getDefaultInstance(props, new Authenticator() {
					protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
						return new javax.mail.PasswordAuthentication(username, password);
					}
				});
				URLName url = new URLName(protocol, "serveurmail","25", "", username, password);
		com.sun.mail.smtp.SMTPSSLTransport transport = new com.sun.mail.smtp.SMTPSSLTransport(session, url);
		transport.setStartTLS(true);
		}
		}
		session.setDebug(true);
		try {
		Message mesg = new MimeMessage(session);
		mesg.setFrom(new InternetAddress("sendername");
mesg.setRecipients(Message.RecipientType.TO,InternetAddress.parse("toto@gmail.com", false));
mesg.setSubject("mailObjet");
mesg.setText("mailText");
Transport.send(mesg);		
		}
        catch (MessagingException me)
        {
        	me.printStackTrace();
        }
    }

Filtered HTML

Plain text

CAPTCHA
Cette question permet de vérifier que vous n'êtes pas un robot spammeur :-)
 FFFF  ZZZZZ  V     V  FFFF  RRRR  
F Z V V F R R
FFF Z V V FFF RRRR
F Z V V F R R
F ZZZZZ V F R RR