Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

NO SKYPE .. please just answer here .. Prepare a text file that contains the fol

ID: 3539296 • Letter: N

Question

NO SKYPE .. please just answer here ..

      Prepare a text file that contains the following information:

Name

Nick Name

Friend

Email

Abdullatif

Bu-Shmais

Yes

latif@yahoo.com

Mariam

Maryoom

No

mariam@gmail.com

Laila

Lulu

Yes

laila@gmail.com

Using JavaMail, write a program that will be used to send out emails on special occasions to everyone in the list based on whether they are friends or not.

First prompt the user with a JOptionPane.showInputDialog asking for the subject line, then for his name and finally his nick name.

The message will be in the following format, based on whether the contact is a friend or not =>

FOR CLOSE FRIENDS

Subject: (Input from the JOptionPane)

Dear (Nick Name from the text file),

I just wanted to wish you a wonderful day on this occasion. You are very dear to me and I want you to know that.

Your dear friend,

(Your Nick Name from the JOptionPane)

FOR OTHERS

Subject: (Input from the JOptionPane)

Dear (Name from the text file),

Have a good holiday,,

(Your Name from the JOptionPane)

Name

Nick Name

Friend

Email

Abdullatif

Bu-Shmais

Yes

latif@yahoo.com

Mariam

Maryoom

No

mariam@gmail.com

Laila

Lulu

Yes

laila@gmail.com

Explanation / Answer

Its fully executable code.

just install JavaMail from

http://www.oracle.com/technetwork/java/javamail/index.html


Put your username and password, and run it.

Rate me 5 stars



import java.util.*;

import java.io.*;

import javax.swing.*;


class Mukesh

{

public static void main(String args[]) throws IOException

{

File file=new File("Contact.txt");

if(!file.exists())

{

file.createNewFile();

}

FileWriter fw=new FileWriter(file.getAbsoluteFile());

BufferedWriter bw=new BufferedWriter(fw);

bw.write("Abdullatif ");

bw.write("Bu-Shmais ");

bw.write("Yes ");

bw.write("latif@yahoo.com ");

bw.newLine();

bw.write("Mariam ");

bw.write("Maryoom ");

bw.write("No ");

bw.write("mariam@gmail.com ");

bw.newLine();

bw.write("Laila ");

bw.write("Lulu ");

bw.write("Yes ");

bw.write("laila@gmail.com ");

bw.newLine();

bw.close();

String subject= JOptionPane.showInputDialog("Subject Line");

String name= JOptionPane.showInputDialog("Name");

String nickname= JOptionPane.showInputDialog("Nick Name");

String closefriend="No";

String email="";

String name1="";

String nickname1="";

String closefriend1="";

Scanner s =new Scanner(new BufferedReader(new FileReader("Contact.txt")));

int found=-1;

while(s.hasNext())

{

name1=s.next();

nickname1=s.next();

closefriend1=s.next();

email=s.next();

if(name1.equals(name1))

{

closefriend1=closefriend;

found++;

}

}

if(found==-1)

{

JOptionPane.showConfirmDialog(null,name+" not found");

}

else

{

if(closefriend.equals("Yes"))

{

final String username = "username@gmail.com";

final String password = "password";

Properties props = new Properties();

props.put("mail.smtp.auth", "true");

props.put("mail.smtp.starttls.enable", "true");

props.put("mail.smtp.host", "smtp.gmail.com");

props.put("mail.smtp.port", "587");

Session session = Session.getInstance(props,

new javax.mail.Authenticator() {

protected PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication(username, password);

}

});

try {

Message message = new MimeMessage(session);

message.setFrom(new InternetAddress("username@gmail.com"));

message.setRecipients(Message.RecipientType.TO,

InternetAddress.parse(email));

message.setSubject(subject);

message.setText("Dear "+nickname1+", I just wanted to wish you a wonderful day on this occasion. You are very dear to me and I want you to know that. "+nickname);

Transport.send(message);

System.out.println("Message has been successfully sent");

} catch (MessagingException e)

{

throw new RuntimeException(e);

}

}

else

{

final String username = "username@gmail.com";

final String password = "password";

Properties props = new Properties();

props.put("mail.smtp.auth", "true");

props.put("mail.smtp.starttls.enable", "true");

props.put("mail.smtp.host", "smtp.gmail.com");

props.put("mail.smtp.port", "587");

Session session = Session.getInstance(props,

new javax.mail.Authenticator() {

protected PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication(username, password);

}

});

try {

Message message = new MimeMessage(session);

message.setFrom(new InternetAddress("username@gmail.com"));

message.setRecipients(Message.RecipientType.TO,

InternetAddress.parse(email));

message.setSubject(subject);

message.setText("Dear "+name1+", Have a good holiday,, "+name);

Transport.send(message);

System.out.println("Message has been successfully sent");

} catch (MessagingException e)

{

throw new RuntimeException(e);

}

}

}

}

}