Javax.Mail Query Help Me Please
Hi all
I made a GUI based code to send mails using javax.mail api now i made my code in Net Beans and i just made a library of javax.mail and attached it to my project
Everything is working fine using netbeans
The problem arises when i create a jar file of it and try to run in other computer there the mail does not send
The problem is that javax.mail api is not in that PC so how can i add javax.api in that api without manually adding javax.mail in the system path of PC
This problem is also in my PC too even though i have added the path in system variable path but even then i cant run the jar file
Help me please
Re: Javax.Mail Query Help Me Please
Hello, either you can shadow the mail.jar into your programs jar as in deflate it and pack the contents into your jar or you can simply make sure your classpath is correct in the manifest file and make sure you ship the mail.jar with your program.
// Json
Re: Javax.Mail Query Help Me Please
Well thanks for ur reply can u give me a snippet so that i can understand what you are trying to express
Please
Thanks
Re: Javax.Mail Query Help Me Please
See Adding Classes to the JAR File's Classpath (The Java™ Tutorials > Deployment > Packaging Programs in JAR Files)
At the bottom of that page you can see that you can specify a classpath entry in the manifest file.
Quote:
Class-Path: mail.jar
Now all you need to do is have the mail.jar next to your own jar file and it should find the mail.jar file and put it on the classpath.
// Json
Re: Javax.Mail Query Help Me Please
hi i tried your method but when i execute the jar file it gives me an error
"Cant find main class GUI"
my manifest file is
Code :
Class-Path: mail.jar
Main-Class: GUI
Re: Javax.Mail Query Help Me Please
When you specify Main-Class: GUI it means that java will try to locate a class file GUI.class in the root of the jar file. This needs to be the fully qualified package/class name of the class containing the public static void main(String... arguments) method.
// Json
Re: Javax.Mail Query Help Me Please
well i am sending you my code you tell me what should be my manifest file
GUI.java
Code :
package sendmail;
import sendmail.sending;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class GUI implements ActionListener
{
private Frame f;
private Button b1,b2;
private TextField from,to,pwd,sub;
private TextArea body;
private Label l1,l2,l3,l4,l5;
private Panel p1,p2,p3,p4,p5,p6;
public GUI()
{
f=new Frame("Send Mail");
f.addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e) { actionExit(); } });
from=new TextField(30);
pwd=new TextField(30);
pwd.setEchoChar('*');
to=new TextField(30);
sub=new TextField(30);
body=new TextArea(30,100);
b1=new Button("Send");
b2=new Button("Reset");
l1=new Label("From (ID) *");
l2=new Label("Password *");
l3=new Label("To *");
l4=new Label("Sub *");
l5=new Label("Body");
p1=new Panel();
p2=new Panel();
p3=new Panel();
p4=new Panel();
p5=new Panel();
p6=new Panel(new GridLayout(3,1));
}
public void launch() throws Exception
{
f.setLayout(new BorderLayout());
p1.add(l1);
p1.add(from);
p1.add(l2);
p1.add(pwd);
p2.add(l3);
p2.add(to);
p3.add(l4);
p3.add(sub);
p4.add(body);
p5.add(b1);
p5.add(b2);
p6.add(p1);
p6.add(p2);
p6.add(p3);
f.add(p6,BorderLayout.NORTH);
f.add(p4,BorderLayout.CENTER);
f.add(p5,BorderLayout.SOUTH);
b1.addActionListener(this);
b2.addActionListener(this);
f.pack();
f.setVisible(true);
}
private void actionExit()
{
System.exit(0);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getActionCommand().equals("Send"))
{
String fr=from.getText();
String p=pwd.getText();
String s=sub.getText();
String b=body.getText();
StringTokenizer st1=new StringTokenizer(to.getText(),",");
String[] t=new String[st1.countTokens()];
int i=0;
while(st1.hasMoreTokens())
{
t[i]=st1.nextToken();
i++;
}
System.out.println("Sending the data to sending class--->");
sending s1=new sending(fr,b,s,t,p);
String result=s1.send();
body.setText("");
body.setText(result);
}
else
{
from.setText("");
pwd.setText("");
to.setText("");
sub.setText("");
body.setText("");
}
}
public static void main(String args[]) throws Exception
{
GUI a=new GUI();
a.launch();
}
}
sending.java
Code :
package sendmail;
import java.security.Security;
import java.util.Properties;
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 sending
{
private static final String SMTP_HOST_NAME = "smtp.gmail.com";
private static final String SMTP_PORT = "465";
private static final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
String MsgTxt=null;
String Subject=null;
String From=null;
String pwd=null;
String[] too;
public sending(String fr,String msg,String sub,String[] fro,String p)
{
MsgTxt=msg;
Subject=sub;
From=fr;
pwd=p;
too=fro;
for(int i=0;i<too.length;i++)
{
System.out.println(too[i]);
}
}
public String send()
{
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
try
{
sendSSLMessage(too,Subject,MsgTxt,From,pwd);
}catch(Exception e)
{
System.out.println(e);
}
return("Sucessfully Sent mail to User(s)");
}
public void sendSSLMessage(String recipients[], String subject,String message, String from,String pwd) throws MessagingException
{
boolean debug = true;
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.port", SMTP_PORT);
props.put("mail.smtp.socketFactory.port", SMTP_PORT);
props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
props.put("mail.smtp.socketFactory.fallback", "false");
final String from1=from;
final String pwd1=pwd;
Session session = Session.getDefaultInstance(props,new javax.mail.Authenticator()
{protected PasswordAuthentication getPasswordAuthentication()
{return new PasswordAuthentication(from1,pwd1);}});
session.setDebug(debug);
Message msg = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
from=null;
recipients=null;
pwd=null;
subject=null;
message=null;
}
}
Re: Javax.Mail Query Help Me Please
Try altering your main-class to this.
Quote:
Main-Class: sendmail.GUI
// Json
Re: Javax.Mail Query Help Me Please
See i made this code in Netbeans and used the mail.jar as library and included to my project
But now i just copied the .class files to desktop and copied mail.jar file to desktop
and on the desktop i am making the manifest.mf
So using sendmail.GUI will not help
Re: Javax.Mail Query Help Me Please
But the GUI.class have to be in a sendmail folder because of the package declaration at the top in your code or it wont work anyways.
Could you try attaching the files here and I will try to create a jar file for you when I have some more spare time.
// Json
Re: Javax.Mail Query Help Me Please
well thanks i forgot i had a package sorry to disturb you now it is functioning thanks anyways