0% found this document useful (0 votes)
53 views2 pages

Relay 465

1. Import a .cer certificate file into the Java keystore using the keytool command to enable SSL communication with the SMTP server. 2. List the imported certificate to verify it was added correctly. 3. Send an email using JavaMail and the SMTP server details, authenticating using the credentials and enabling SSL via the certificate.

Uploaded by

Raaju- Sys.Admin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views2 pages

Relay 465

1. Import a .cer certificate file into the Java keystore using the keytool command to enable SSL communication with the SMTP server. 2. List the imported certificate to verify it was added correctly. 3. Send an email using JavaMail and the SMTP server details, authenticating using the credentials and enabling SSL via the certificate.

Uploaded by

Raaju- Sys.Admin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1. Import the given .

cer file into your server with Keytool command

keytool -import -noprompt -trustcacerts -alias relay.nic.in -file PATH.cer


-keystore "jssecacert" file path(file available in where java installed )

Enter keystore password:


Re-enter new password:
Certificate was added to keystore

2. List certificate file

keytool -list -keystore ..\lib\security\jsscacert -alias relay.nic.in

3. Now test with the given JAVA code:

import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class EmailTest {

private static final String SMTP_HOST_NAME = "relay.nic.in";


private static final String SMTP_AUTH_USER = "[email protected]"; //
user's email address
private static final String SMTP_AUTH_PWD = "password; //
Password

public static void main(String[] args) throws Exception {

new EmailTest().test("[email protected]"); // Recipient email address

public void test(String email) throws Exception {


Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.debug", "true");

Authenticator auth = new SMTPAuthenticator();


Session mailSession = Session.getDefaultInstance(props, auth);
Transport transport = mailSession.getTransport();
String msg = "Test Mail";
MimeMessage message = new MimeMessage(mailSession);
message.setContent(msg, "text/html; charset=utf-8");
message.setSubject("Test Mail");
message.setFrom(new InternetAddress("[email protected]")); // from address
message.addRecipient(Message.RecipientType.TO, new
InternetAddress(email));

transport.connect();
transport.sendMessage(message,
message.getRecipients(Message.RecipientType.TO));
transport.close();
}

private class SMTPAuthenticator extends javax.mail.Authenticator {

public PasswordAuthentication getPasswordAuthentication() {


String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
return new PasswordAuthentication(username, password);
}
}

You might also like