Unable to send mail using javamail through gmail
can anyone plz help me by sending the code to [email protected] send mail through gmail server as i always get exception of authentication failed even when i supply correct userid & password
Include the following when setting your mail properties:
props.put("mail.smtp.auth", "true");
Similar Messages
-
Getting exceptions while sending mail using javamail api
Hi to all
I am developing an application of sending a mail using JavaMail api. My program is below:
quote:
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public class sms
public static void main(String args[])
try
String strstrsmtserver="smtp.bol.net.in";
String strto="[email protected]";
String strfrom="[email protected]";
String strsubject="Hello";
String bodytext="This is my first java mail program";
sms s=new sms();
s.send(strstrsmtserver,strto,strfrom,strsubject,bodytext);
catch(Exception e)
System.out.println("usage:java sms"+"strstrsmtpserver tosddress fromaddress subjecttext bodyText");
System.exit(0);
public void send(String strsmtpserver,String strto,String strfrom ,String strsubject,String bodytext)
try
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties p=new Properties(System.getProperties());
if(strsmtpserver!=null)
p.put("mail.transport.protocol","smtp");
p.put("mail.smtp.host","[email protected]");
p.put("mail.smtp.port","25");
Session session=Session.getDefaultInstance(p);
Message msg=new MimeMessage(session);
Transport trans = session.getTransport("smtp");
trans.connect("smtp.bol.net.in","[email protected]","1234563757");
msg.setFrom(new InternetAddress(strfrom));
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(strto,false));
msg.setSubject(strsubject);
msg.setText(bodytext);
msg.setHeader("X-Mailer","mtnlmail");
msg.setSentDate(new Date());
Transport.send(msg);
System.out.println("Message sent OK.");
catch(Exception ex)
System.out.println("here is error");
ex.printStackTrace();
It compiles fine but showing exceptions at run time.Please help me to remove these exceptions.I am new to this JavaMail and it is my first program of javamail.Please also tell me how to use smtp server.I am using MTNL 's internet connection having smtp.bol.net.in server.
exceptions are:
Here is exception
quote:
Javax.mail.MessagingException:Could not connect to SMTP host : smtp.bol.net.in, port :25;
Nested exception is :
Java.net.ConnectException:Connection refused: connect
At com.sun.mail.smtp.SMTPTransport.openServer<SMTPTransport.java:1227>
At com.sun.mail.smtp.SMTPTransport.protocolConnect<SMTPTransport.java:322>
At javax.mail.Service .connect(Service.java:236>
At javax.mail.Service.connect<Service.java:137>
At sms.send<sms.java:77>
At sms.main<sms.java:24>Did you find the JavaMail FAQ?
You should talk to your ISP to get the details for connecting to your server.
In this case I suspect your server wants you to make the connection on the
secure port. The FAQ has examples of how to do this for GMail and Yahoo
mail, which work similarly. By changing the host name, these same examples
will likely work for you. -
Unable to SEND mail using Activesync in Exchange 2010 server on iPhone or Windows Mobile 6.1
Hi All,
We've been setting up a new SBS 2011 server for a client this week. Everything is working, except the staff have 4 x iPhones to connect with Exchange ActiveSync.
There are 2 x iPhone 4's and 2 x iPhone 3Gs's. We can setup the Exchange accounts on each of the phones and they are all able to sync mail and calender etc with the server.
The problem we have is when any of them try to send mail from the phone, it gives an error : "Cannot Send Mail - An error occurred while delivering this message" and it sits in the outbox on the phone.
The newsgroups and forums are littered with people having issues with IOS4 and Exchange 2010 but most of these are from June-August 2010 when IOS4 version was around 4.00 or 4.01
A lot of these people had iPhone 3 handsets running with IOS 3.1.3 which worked with Exchange 2010 but when they upgraded to IOS 4, they had this problem sending mail.
It seems that for most of them, the fix came in the form of IOS version 4.1 which fixed the send issue for them.
We have a variety of Hansets and IOS versions (including an iPhone 3Gs running IOS 3.1.3) but are unable to send mail from any of them:
iPhone 3Gs IOS 3.1.3
iPhone 3Gs IOS 4.3.3
iPhone 4 IOS 4.3.3
iPhone 4 IOS 4.3.5
I was surprised that the iPhone 3Gs running 3.1.3 was unable to send either as nearly all the forums etc I read with this issue said the iPhone 3's worked with that IOS version.
Today we used a test iPhone 4 handset from our office to connect to an almost identical Small Business Server 2011 we setup two weeks ago for another client.
The test iPhone 4 was able to connect, Sync and Send email on that server but when set it to connect to this SBS 2011 server, it gets the "Cannot Send Mail" message the same as the others. So clearly the handset is working (on the other server at least),
it must be something misconfigured in this Exchange server right?
We ran the Exchange Remote Connectivity Analyser on the Exchange server and got green ticks across the board.
Outlook Web App and Outlook Anywhere both work normally. Everything we can test on the Exchange server works except sending from any iPhone.
Having said all that, I just setup a Windows Mobile 6.1 handset to sync with the Exchange 2010 server as a test, and it appears to have the same issue.
It will connect & Sync Mail, Contacts and Calendar but if trying to send an email from the phone, it will just sit in the outbox.
Does anyone have some insight into what the problem may be?Further to this .. I found the solution on a MS Exchange 2010 support forum.
It was not a certificate or firewall issue, looks as thought the “Accepted Domains” in Exchange Mgmt Console –
Org Config – Hub Transport cannot have any spaces in the name field.
I had some spaces and the emails were not downloading fully and able to send. Once I removed the spaces from the Name field and
restarting the Exchange and IIS services emails were now being sent and received ok.
Check
out :
http://social.technet.microsoft.com/Forums/en-US/exchangesvrmobility/thread/321eae51-9cbd-4a5e-85c1-68d8f7b523c3
This
is good one to add to your knowledge bank in case you come across it in the future.
Rgds Gerry -
Delivery Receipt After Sending Mail Using JavaMail ?
Hi Friends,
I have written an application using JavaMail which would be used to send mail
using my organisation's SMTP Server.I would like to include the following functionality in it.Just as
Microsoft's Outlook has an option to get Delivery Receipt of the mail and Read Receipt of the mail sent
(Provided the email Client supports it) i would like to have a similar option in my application to.I would like to of how i can do it using JavaMail.I heard that basically we need to set some SMTP properties which the Mail Transfer Agent would recognize and send us the Delivery and Read Receipts.But,i am not sure of what those properties.Can anyone help me regarding this ?You might look into creating a custom header that provides a return reciept to the email address you specify. I'm not 100% sure that all mail servers support this but you might want to look into it as a solution.
-Dave -
"Unable to send mail" using Verizon email account
No matter what I try, my Incredible will not send an email using my Verizon email account. I receive emails but cannot send. I've verified the account settings numerous times and the verifications always work. But I still get the "Unable to send mail" message. Initially I thought it was the port but I've tried both 25 and 587. Neither work. I know I've sent messages before but it's been a while. Anyone have any ideas?
I tried SSL with 25 and 587 (Verizon recommendation). Still no go.
BTW, there isn't any way to save the Mail size limit and Download options is there. Every time I go thru this I have to go back and set these up again.
Thanks again for your help. -
Send mail using CL_BCS through function module, run in background task.
Hi,
I am running a function module in Background task. in this function module I am sending mail using CL_BCS class.
but mail is not generated. if I run the same function Module in foreground mail generated successfully....
can anyone please tell me the reason behind this.Hi i realise that The LIST_TO_ASCII thing is not working correctly in background because the the list-processing in beckground is working not the same as in dialog i think.
I can only get the last page of the list out when running in background. Any solution to this?
my code:
CALL FUNCTION 'LIST_TO_ASCI'
EXPORTING
list_index = sy-lsind
TABLES
list_dyn_ascii = downtab
EXCEPTIONS
empty_list = 1
list_index_invalid = 2
OTHERS = 3.
IF sy-subrc NE 0.
EXIT.
ENDIF.
Thanks ,
LH -
How to setup SMTP server in PC so as to send mails using JavaMail
Hi,
From forums i got it cleared that we can use JavaMail to send emails. I also got two sample codes about getting it done. But in the code its asks address of the host of SMTP server. I dont have any SMTP server. But i am writing a Library Application in which an email must be sent to users automatically when thier books are in overdue.
Where can i get SMTP server to be installed on my PC so that i can use it send mails through Javamail API.
ThanksIsnt there any way setup SMTP server on own pc?? I just want to send mails in my local area network.
-
Java Session problem while sending mail(using javamail) using Pl/SQL
Hello ...
i am using Java stored procedure to send mail. but i'm getting java session problem. means only once i can execute that procedure
pls any help.props.put("smtp.gmail.com",host);I doubt javamail recognizes the 'smtp.gmail.com' property. I think it expects 'mail.host'. Of course since it cannot find a specified howt it assumes by default localhost
Please format your code when you post the next time, there is a nice 'code' button above the post area.
Mike -
Hi!
I am new to JavaMail and trying to execute a simple code to send mail.
I can compile the code without any errors. But when I try to run it, I get following error:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException
I have my mail.jar and activation.jar in \lib\ext.
the code is demo code from sun, in their demo files that one gets with javamail.
Thanks,
bandyaYou have to put the paths if mail.jar and activation.jar in the system CLASSPATH.
or you can do this before executing the java program
in command prompt
set CLASSPATH=%CLASSPATH%;c:\mail.jar;c:\activation.jar
assuming the jar are in c:\ . -
Exception while sending mail using javamail
below i am using the code to send a mail to [email protected]
but it is giving exception
"class com.sun.mail.smtp.SMTPSendFailedException: 554 <[email protected]>: Recipient address rejected: Relay access denied"
please can any body help me to solve this problem
Properties props = new Properties();
props.put("mail.smtp.host", "xxxxxxxxxxxxx");
Session s = Session.getInstance(props,null);
MimeMessage message = new MimeMessage(s);
InternetAddress from = new InternetAddress("[email protected]");
message.setFrom(from);
InternetAddress to = new InternetAddress("[email protected]");
message.addRecipient(Message.RecipientType.TO, to);
message.setSubject("Test from JavaMail.");
message.setText("Hello from JavaMail!");
Transport.send(message);I was getting the same error as the others, and I added authentication, but it still gives me the error.
All "AutomailingUtility" constants are strings
public class SMTPSender {
private Session session;
public SMTPSender() {
Properties props = new Properties();
props.setProperty("mail.smtp.host", AutomailingUtility.HOST);
props.put("mail.smtp.auth", AutomailingUtility.AUTH);
Authenticator auth = new MyAuthenticator(AutomailingUtility.USERNAME, AutomailingUtility.PASSWORD);
session = Session.getInstance(props, auth);
public void sendMessage(String toUser, String message, String subject) {
try {
Message msg = new MimeMessage(session);
msg.setSubject(subject);
msg.setSentDate(new Date());
InternetAddress ia = new InternetAddress(AutomailingUtility.FROM_ADDRESS);
msg.setFrom(ia);
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toUser));
msg.setText(message);
Transport.send(msg);
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
any ideas? -
Help me in sending mails using Javamail
Hi guys this is my first Topic on thid Forum, expecting 'the best' response from any of u.
I just want a class that takes a message and recipients address & sends a mail.
I would really be obliged if some one can give me a very little class for it.
Thanx in advanceWhy not look at the demos in the JavaMail download package? and if u have problems with them, post to the JavaMail forum!
-
Need help with MacPro mail and sending email currently not functioning.
Troubleshooting sending and receiving email messages
Troubleshooting sending email messages -
Cant send mail using javamail - relay problem
Hi all,
I have provided the correct user,passwd,host.
This is the error i am getting -
javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
javax.mail.SendFailedException: 530 5.7.1 Relaying not allowed: [email protected]
Pl tell me how can i solve the problemRelaying is described in the FAQ.
-
Unable to send mail with different fonts and colors
Hi All,
here is the explanation for my problem:
I am sending mail using javamail. when i send the text with different font and color its not received in the same way. it is simply sending as plain text.
Please help me on this issue.
Thanks
NGHello,
I am trying to develop an email application. It consists on sending email from [email protected] to [email protected]
How can I do this in java ?
I am using this software but it works only with gmail !!
* Send Email to the webmaster
String d_email = "[email protected]",
d_host = "smtp.gmail.com",
d_port = "465",
m_to = "[email protected]",
m_subject = "Email from user";
Properties props = new Properties();
props.put("mail.smtp.user", d_email);
props.put("mail.smtp.host", d_host);
props.put("mail.smtp.port", d_port);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.debug", "true");
props.put("mail.smtp.socketFactory.port", d_port);
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
SecurityManager security = System.getSecurityManager();
try
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
//session.setDebug(true);
MimeMessage msg = new MimeMessage(session);
msg.setText("This is a message from: "+UserEmail+"\n "+UserMessage);
msg.setSubject(m_subject);
msg.setFrom(new InternetAddress(d_email));
msg.setSentDate(new Date());
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(m_to));
Transport.send(msg);
catch (Exception ex)
ex.printStackTrace();
out.println("Messaging ERROR: " + ex);
out.println(stack2string(ex));
if(ex.getMessage().compareTo("")!=0)
check = "Message NOT SENT " + ex.getMessage();
private class SMTPAuthenticator extends javax.mail.Authenticator
public PasswordAuthentication getPasswordAuthentication()
return
new PasswordAuthentication("[email protected]", "pwd");
}please advice -
I'm unable to send and receive email through Apple Mail 4. I've checked my settings on Preferences, and my password to Gmail is up to date for syncing with IMAP, but it still won't connect. Suggestions?
I think it's trying to open it in a gMail eMail & is losing your gMail password that it needs log into gMail, but not 100% positive.
Have you tried Right clicking or Control+click on the eMail link & choose Copy? Works on some, not others.
Maybe you are looking for
-
Unable to open a query view in web analyzer
Hi All In web analyzer i have saved a Query view, Using save as tab. when i tried to open that Query view through open tab in web analyzer it is throughing some exceptional error. Is this the right way to access the saved query view, can anyone help
-
in numbers, how would I make a line for each family (100+) a column for each fundraiser. and at mid year, and year end be able to print an alphabetical listing? example: entertainment books Chip Shoppe Yankee Candle Smith
-
CRM Pricing error after 5000 seconds with CRM_ORDER_MAINTAIN in background
Hi, This is Rajender. I am using function module CRM_ORDER_MAINTAIN to create sales order. I am facing a error while creating sales order from text file. while uploading 15000 records it is taking more than 5000 seconds. But after 5000 seconds the ba
-
My kaspersky internet security is not working with firefor 5.0 why?
I recently updated my firefox to 5.0 version and now it says my add onns are not compatible. i have kaspersky internet security and the new firefox says it is not compatible for it.
-
Hi, I just rented Transformers HD through Apple TV and it started downloading, but then it stopped and gave "Download Error 8008". No matter how many times I click Check for Purchases it won't resume downloading. And I know the problem has nothing to