मैं एक साधारण मेल प्रेषक वर्ग लिखने की कोशिश कर रहा हूं जो तर्कों का एक समूह प्राप्त करेगा और उनका उपयोग करके हमारे एक्सचेंज 2010 सर्वर का उपयोग करके एक ईमेल भेज दिया जाएगा। प्रमाणीकरण इत्यादि ठीक काम करने लगते हैं, जब कोड वास्तव में ईमेल भेजने की कोशिश कर रहा है तो मुझे निम्नलिखित अपवाद मिल रहा है (मुझे लगता है)। मैंने यह सुनिश्चित किया है कि प्रमाणीकरण काम कर रहा है और मुझे सत्र से वापस परिवहन मिलता है, लेकिन फिर भी यह विफल हो जाता है। क्या कोई इस बात की तरह कुछ छोड़ सकता है कि मैं गलत क्या कर रहा हूं या लापता हूं? धन्यवाद।जावामेल - javax.mail.MessagingException
अपवाद:
javax.mail.MessagingException: [EOF]
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1481)
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1512)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634)
at javax.mail.Transport.send0(Transport.java:189)
at javax.mail.Transport.send(Transport.java:140)
at com.ri.common.mail.util.MailSender.sendHTMLEmail(MailSender.java:75)
at com.ri.common.mail.util.MailSender.main(MailSender.java:106)
प्रासंगिक कोड:
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class MailSender
{
public static void sendHTMLEmail(String fromEmailId, String toEmailId, String host, String hostUserName,
String hostPassword, String mailSubject, String mailBody)
{
// Get system properties.
Properties props = System.getProperties();
// Setup mail server
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
final String hostUName = hostUserName;
final String hPassword = hostPassword;
Authenticator authenticator = new Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(hostUName, hPassword);
}
};
// Get the default Session object.
Session session = Session.getDefaultInstance(props, authenticator);
try
{
// Create a default MimeMessage object.
MimeMessage message = new MimeMessage(session);
// Set From: header field of the header.
message.setFrom(new InternetAddress(fromEmailId));
// Set To: header field of the header.
message.addRecipient(Message.RecipientType.TO, new InternetAddress(toEmailId));
// Set Subject: header field
message.setSubject(mailSubject);
// Send the actual HTML message, as big as you like
message.setContent(mailBody, "text/html");
// Send message
Transport.send(message, message.getAllRecipients());
System.out.println("Sent message successfully....");
}
catch(Exception mex)
{
mex.printStackTrace();
}
}
public static void main(String[] args)
{
String to = "[email protected]";
String from = "[email protected]";
String host = "correctHostForExch2010";
String user = "correctUser";
String password = "CorrectPassword";
String subject = "Test Email";
String body = "Hi there. This is a test email!";
MailSender.sendHTMLEmail(from, to, host, user, password, subject, body);
}
}
संपादित करें: मैं डिबगिंग के बारे में बदल गया और यह
MAIL FROM:<[email protected]> 530 5.7.1 Client was not authenticated
DEBUG SMTP: got response code 530, with response: 530 5.7.1 Client was not authenticated.
कि क्यों होगा कहते हैं जब सत्र प्रमाणीकरण succeded?
आप डिबग मोड को सक्रिय कर सकते हैं , ताकि आप देख सकें कि एसपीपीटी सर्वर पर आपका ऐप क्या कह रहा है, बातचीत के अंत में आपको त्रुटि का संकेत देने वाला कुछ देखना चाहिए। – Alex
हाय एलेक्स, धन्यवाद! मैंने डिबगिंग चालू कर दी और यह मेल से कहता है: <[email protected]> 530 5.7.1 क्लाइंट प्रमाणीकृत नहीं किया गया DEBUG SMTP: प्रतिक्रिया कोड 530 मिला, प्रतिक्रिया के साथ: 530 5.7.1 क्लाइंट प्रमाणीकृत नहीं था। ऐसा क्यों होगा जब सत्र प्रमाणीकरण उत्तराधिकारी हो? – legendofawesomeness
मैंने अभी देखा है कि एक्सचेंज उपयोगकर्ता के कुछ संस्करणों में निम्न प्रारूप 'उपयोगकर्ता @ डोमेन' या' डोमेन \\ उपयोगकर्ता 'में से एक होना चाहिए, यदि इस दौरान किसी भी मदद की जा सकती है। – Alex