Home Answers Viewqa JSP-Servlet JavaMail and Gmail in Windows

 
 


Khushbu Arora
JavaMail and Gmail in Windows
0 Answer(s)      3 years ago
Posted in : JSP-Servlet

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 Pages:
JavaMail and Gmail in Windows - JSP-Servlet
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
JavaMail and Gmail - JSP-Servlet
JavaMail 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
gmail access using javamail API
gmail 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
javamail in jsp - JavaMail
javamail 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 - JavaMail
Mailing  Dear Friends, How can i send mails to yahoo,gmail,other mail servers using javamail using a jsp file. Please help me
Java Mail exception - JavaMail
Java 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
JAVA Mail - JavaMail
JAVA Mail  Hi! I am trying to send the mail using SMTP of gmail. program was compiled successfully. when i am trying to execute that program it is showing error --- Must issue STARTTLS command first... How to avoid
gmail authentication
gmail authentication  Hi... there... I observed that if we open gmail and in that in box then there will be some url like
gmail authentication
gmail authentication  Hi... there... I observed that if we open gmail and in that in box then there will be some url like
gmail authentication
gmail authentication  Hi... there... I observed that if we open gmail and in that in box then there will be some url like
gmail authentication
gmail authentication  Hi... there... I observed that if we open gmail and in that in box then there will be some url like
gmail authentication
gmail authentication  Hi... there... I observed that if we open gmail and in that in box then there will be some url like
gmail authentication
gmail authentication  Hi... there... I observed that if we open gmail and in that in box then there will be some url like
Java Mail API - JavaMail
Java Mail API  Hi! I wish u advanced happy new year to all of ur team members.... My question is.. I want to read attachments in my gmail account using java mail api... i got code from our roseindia.net i.e.
Apache james - JavaMail
windows server than go to services and then stop the service ?Simple Mail
gmail authentication
gmail 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
Windows 8 versus Android
Windows 8 has launched at a time when the much thrived smart phone and tab... the potential success of all the platforms and in talking of Windows 8 versus Android... android is a platform that almost swept majority of smart phone devices Windows phone
why mails are sending from the linux server - JavaMail
why mails are sending from the linux server  Mails are not sending from the linux server.We have 3 systems. server system is windows 2003 server... java application,mail are not sending .Mail server is installed on windows 2003
JAVAMAIL API - JavaMail
JAVAMAIL API  This is my code, but i got unnecessary data like ???]???????????? € ??? this how to avoid this WELCOME  
Features of Epic Browser for Windows
Bharadwaj. There is a long list of features of Epic browser for Windows. Just... specifically to the Facebook or Twitter or Gmail website, Epic has a side widget... widget linked to Gmail and Create Edit Document that take away the need of MS
New Gmail Version for iPhone from Google, New iPhone Gmail, iPhone 3.0 Gmail
New Gmail for Apple iPhone Google launched the new version of its popular email service Gmail for the iPhone with a host of specially designed features... in the desktop version of Gmail. If you need to search your mail you can just key
JavaMail API usage - JavaMail
JavaMail 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 - JavaMail
JavaMail 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 - JavaMail
JavaMail 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 - JavaMail
java  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 - JavaMail
java  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
forgotpassword - JavaMail
with running example. http://www.roseindia.net/javamail/ Thanks
extract content from javamail - JavaMail
extract 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
getting contacts from gmail - JSP-Servlet
getting contacts from gmail  hi there, would you please tell me step by step how can i integrate the gmail contacts with my web application. please reply me asap. I'll be greatfull to you. Rajesh
multiple file upload at a time like gmail
multiple file upload at a time like gmail  I want to upload multiple files at a time like gmail. is there any possiblity/solution to do that?   Hi Friend, Please visit the following link: Upload Multiple Files Thanks

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.