JavaMail and Gmail in Windows
Hello!
I made a java program to send and receive emails through Gmail SMTP server. It worked fine in Windows 7 but when I try to run the same program in Windows XP in a different machine, then the mail is not going. Either Messaging exception or SendMail exception comes. I have used JDK1.6 and NetBeans 5.5 to build this program.
Kindly let me know whether the issue is of operating system (in this case changes need to made accordingly) or some setting needs to be done in NetBeans, which somehow was taken by default in Windows 7.
The program is=
/*
* SendMail.java
*
* Created on 19 April, 2010, 10:14 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package utility;
import java.io.Console;
import javax.mail.*;
import javax.mail.internet.*;
//import javax.activation.*;
import java.util.*;
/**
*
* @author Khushbu
* @version
*/
public class SendMail {
String username=null;
String password=null;
/** Creates a new instance of SendMail */
public SendMail() {
}
public void postMail( String recipients[ ], String subject, String message, String from, String pwd) throws MessagingException
{
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
//props.put("mail.smtp.host", "smtp.live.com");
String host="smtp.gmail.com";
props.put("mail.smtps.auth", "true");
// Authenticator a1= new PopupAuthenticator();
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
//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);
// Setting the Subject and Content Type
msg.setSubject(subject);
//msg.setContent(message, "text/plain");
msg.setText(message);
//Transport.send(msg);
username = from;
password = pwd;
Transport t = session.getTransport("smtps");
try {
t.connect(host, username, password);
//t.connect(host, username);
t.sendMessage(msg, msg.getAllRecipients());
} finally {
t.close();
}
}
}
View Answers
Related Tutorials/Questions & Answers:
JavaMail and Gmail in Windows - JSP-ServletJavaMail and
Gmail in Windows Hello!
I made a java program to send and receive emails through
Gmail SMTP server. It worked fine in
Windows 7 but when I try to run the same program in
Windows XP in a different machine
gmail access using javamail APIgmail access using
javamail API how to coonect to
gmail using java...://www.roseindia.net/
javamail/
Hope that it will be helpful for you.
Thanks
.../
javamail/][2]
Thanks
[1]: http://www.roseindia.net/
javamail/
[2]: http
Advertisements
JavaMail and Gmail - JSP-ServletJavaMail and Gmail In my previous question, I forgot to mention that following exception is arising when trapped in catch:
javax.mail.MessagingException: can't determine local email address
Kindly let me know
javamail in jsp - JavaMailjavamail in jsp Hii Sir,
I am working wuth a
javamail programme... other
gmail , yahoo or any other mail servers. I got an exception.... m40sm7925597waf.46 " when i am trying for mailing in
gmail server.
Could you
Mailing - JavaMailMailing Dear Friends,
How can i send mails to yahoo,
gmail,other mail servers using
javamail using a jsp file.
Please help me
gmail authenticationgmail authentication Hi... there... I observed that if we open
gmail and in that in box then there will be some url like
gmail authenticationgmail authentication Hi... there... I observed that if we open
gmail and in that in box then there will be some url like
gmail authenticationgmail authentication Hi... there... I observed that if we open
gmail and in that in box then there will be some url like
gmail authenticationgmail authentication Hi... there... I observed that if we open
gmail and in that in box then there will be some url like
gmail authenticationgmail authentication Hi... there... I observed that if we open
gmail and in that in box then there will be some url like
gmail authenticationgmail authentication Hi... there... I observed that if we open
gmail and in that in box then there will be some url like
gmail authenticationgmail authentication Hi... there... I observed that if we open
gmail and in that in box then there will be some url like
paste in another browser window it asks for authentication how it is possible if anybody knows plz tell
JAVAMAIL API - JavaMailJAVAMAIL API This is my code, but i got unnecessary data like ???]???????????? ??? this how to avoid this
WELCOME
ModuleNotFoundError: No module named 'gmail'ModuleNotFoundError: No module named '
gmail' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
gmail'
How to remove the ModuleNotFoundError: No module named '
gmail'
JavaMail API usage - JavaMailJavaMail API usage Hello sir,
i wrote a program to send a message from one mail account to another
mail account,for that i uses JAVA and JSP two.../
javamail/
Thanks.
Amardeep
JavaMail flagging problems - JavaMailJavaMail flagging problems Hi everyone, I am working on receiving a mail currently. I use a substring "status" to search for the mail's subject line... the following link:
http://www.roseindia.net/
javamail/
Here you will get
JavaMail API - JavaMailJavaMail API Hi My Name is Satish
I have a Problem with Java Mail API when I am doing Maling programme I can able to do single mail and single CC mail but I am not able to do multiple mails How can I do this thing?
Any one can
java - JavaMailjava Hi,
i want to send a mail automatically particular time for every day
so, please reply me Hi Friend,
Please visit the following link:
http://www.roseindia.net/
javamail/
Hope that that above link
java - JavaMailjava How to send out an email using simple java How to send out an email with attachment using simple java Hi Friend,
Please visit the following links:
http://www.roseindia.net/
javamail/
Thanks
extract content from javamail - JavaMailextract content from javamail Hi,
I currently try the example(Read Multipart mail using Java Mail) on
Javamail from the site to receive the e-mail. Then If I going to extract text the message content. What can I do
Java Mail - JavaMailJava Mail how to email using Java mail or automatic generated mail??? Hi Friend,
Please visit the following link:
http://www.roseindia.net/
javamail/
Hope that it will be helpful for you.
Thanks
sending emails - JavaMailsending emails what is the code for sending emails in java Hi Friend,
Please visit the following link:
http://www.roseindia.net/
javamail/
Hope that it will be helpful for you.
Thanks
java mail - JavaMailjava mail how to send a mail without authentication in java ? Hi Friend,
Please visit the following link:
http://www.roseindia.net/
javamail/
Hope that it will be helpful for you.
Thanks
Java Mail exception - JavaMailJava Mail exception Hi!
I am developing E-mail Client (
GMAIL) program using JSP technology. Till now i dont have any problem. From last 3 days while i am connecting to the
Gmail, I am getting the following exception... Whats