Javax.mail.sendfailedexception: Senden fehlgeschlagen; Die verschachtelte Ausnahme ist: Klasse javax.mail.authenticationJava

Java-Forum
Anonymous
 Javax.mail.sendfailedexception: Senden fehlgeschlagen; Die verschachtelte Ausnahme ist: Klasse javax.mail.authentication

Post by Anonymous »

Ich bin neu bei Java Mail und möchte eine E-Mail mit Anhängen senden. Deshalb erstelle ich gerne eine Test-E-Mail mit Beispielcodes aus dem Internet, aber ich bekomme

Code: Select all

javax.mail.sendfailedexception: sending failed;
nested exception is: class javax.mail.authenticationfailedexception
at javax.mail.transport.send0(Transport.java.218)
at javax.mail.transport.send(Transport.java.80)
Ich habe es mit einer anderen Authentifizierung versucht, aber es ist fehlgeschlagen

Code: Select all

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SendEmail
{
public static void main(String [] args)
{

// Recipient's email ID needs to be mentioned.
String to = "[email protected]";

// Sender's email My Office mail server
String from = "[email protected]";
String pass = "Password";
String host = "172.23.5.10";
String port = "25";

// Get system properties
Properties properties = System.getProperties();

// Setup mail server
properties.setProperty("mail.smtp.host", host);
properties.setProperty("mail.smtp.port", port);
properties.setProperty("mail.smtp.auth", "true");

// Get the default Session object.
Session session = Session.getInstance(properties,new MailAuthentication(from,pass));

try{
// Create a default MimeMessage object.
MimeMessage message = new MimeMessage(session);

// Set From: header field of the header.
message.setFrom(new InternetAddress(from));

// Set To: header field of the header.
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));

// Set Subject: header field
message.setSubject("Test Mail");

// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();

// Fill the message
messageBodyPart.setText("Test Mail Success Hari");

// Create a multipar message
Multipart multipart = new MimeMultipart();

// Set text message part
multipart.addBodyPart(messageBodyPart);

// Send the complete message parts
message.setContent(multipart );

// Send message
Transport.send(message);
System.out.println("Sent message successfully....");
}catch (MessagingException mex) {
mex.printStackTrace();
}
}
}

import javax.mail.*
public class MailAuthentication extends Authentication
{

String _user;
String _pass;
public GMailAuthenticator (String username, String password)
{
super();
this._user = username;
this._pass = password;
}
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(_user, _pass);
}
}
Ich habe es auch mit

versucht

Code: Select all

Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
und

Code: Select all

Session session = Session.getDefaultInstance(properties);
und

Code: Select all

Session session = Session.getDefaultInstance(properties);
aber ich erhalte den gleichen Fehler.

Bitte helfen Sie mir, dieses Problem zu lösen

Ich verwende Windows-PCs wie Java-Umgebungsvariablen. Gibt es irgendwelche Schritte für SMTP??

Vielen Dank im Voraus.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post