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?
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. -
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 -
Error while sending mail using script task in ssis 2008
Hi,
i am trying to send mail using ssis 2008 script task.for my requirement i am not able to use send mail task.
code i have used is
declared read only variables system::packagename
Dim PACKAGE As String
PACKAGE = Dts.Variables("System::PackageName").Value.ToString()
Dim myHtmlMessage As MailMessage
Dim mySmtpClient As SmtpClient
myHtmlMessage = New MailMessage("[email protected]", "[email protected]", "PACKAGE STATUS", PACKAGE + "WAS FAILED")
mySmtpClient = New SmtpClient("smtp.gmail.com")
mySmtpClient.Credentials = New NetworkCredential("[email protected]", "mypassword")
mySmtpClient.EnableSsl = True
mySmtpClient.Port = 587
mySmtpClient.Send(myHtmlMessage)
error i am getting is
Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1
Authentication Required. Learn more at
at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at ST_c121e07caaa94c21bb1355d4f753112f.vbproj.ScriptMain.Main()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
can any one tell me where i am going wrongalso getting error as follows
Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1
Authentication Required. Learn more at
at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at ST_c121e07caaa94c21bb1355d4f753112f.vbproj.ScriptMain.Main()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript() -
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.
-
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 -
SMICM error while sending mail using SMTP server
Hi All,
We are not able send mails using SMTP server.
We have made every settings necessary in SCOT, SO16 , SMTP service is activated, default domain is maintained etc
Only things which seems to be wrong is in SMICM trace file.
[Thr 13] *** ERROR => NiBufIConnect: non-buffered connect pending after 5000ms (hdl 29;10.26.24.44:1090) [nibuf.cpp 4608]
[Thr 13] *** WARNING => Connection request from (0/1/0) to host: 10.26.24.44, service: 1090 failed (NIECONN_REFUSED)
[icxxconn_mt.c 2321]
This error is getting repeated in it.
BUt I am not sure why it it trying to hit 10.26.24.44, as we dont have any server by this ip. The ip is only not resolvable from the server.
1 more thing, at OS level, following parameter is maintained in profile :
icm/server_port_1 = PROT=SMTP,PORT=25000,TIMEOUT=180
But in SCOT, under SMTP node PORT is given as 25.
Kindly let me know what going wrong here?
Thanksalso getting error as follows
Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1
Authentication Required. Learn more at
at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at ST_c121e07caaa94c21bb1355d4f753112f.vbproj.ScriptMain.Main()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript() -
Issue while sending mails using classes
Hi Experts ,
i have one issue when i try to send mails using classes cl_document_bcs,cl_cam_address_bcs,cl_bcs etc
ISSUE :
i put some data in selection screen and i get some output ( say i got 5 records), i select 3 records and press some button to trigger mail and mail is send, and now again the OUTPUT screen is shown with sended records but we can not send these records again ............ now i selcect remaining two records and press button to trigger mail and THIS TIME MAIL IS NOT SEND.
amd my code is :
CREATE OBJECT l_document.
CREATE OBJECT l_recipient.
TRY.
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = fp_wa_output
iv_codepage = fp_v_code_page
iv_add_bom = 'X'
IMPORTING
et_solix = l_wa_output_binary
ev_size = l_v_size ).
l_send_request = cl_bcs=>create_persistent( ).
*-->Creating Document
l_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = fp_it_content[]
i_subject = fp_text_48 ) .
*-->Adding Attachment*
CALL METHOD l_document->add_attachment
EXPORTING
i_attachment_type = fp_text_049
i_attachment_size = l_v_size
i_attachment_subject = fp_v_file
i_att_content_hex = l_wa_output_binary.
*-->Add document to send request*
CALL METHOD l_send_request->set_document( l_document ).
* do send delivery info for successful mails
CALL METHOD l_send_request->set_status_attributes
EXPORTING
i_requested_status = 'E'
i_status_mail = 'A'.
*-->Get Sender Object
l_uname = sy-uname.
l_sender = cl_sapuser_bcs=>create( l_uname ).
CALL METHOD l_send_request->set_sender
EXPORTING
i_sender = l_sender.
LOOP AT fp_s_mail INTO l_wa_mail.
l_v_objid = l_wa_mail-low.
l_v_mail = l_v_smtpadr.
TRANSLATE l_v_mail TO LOWER CASE.
l_recipient = cl_cam_address_bcs=>create_internet_address( l_v_mail ).
CALL METHOD l_send_request->add_recipient
EXPORTING
i_recipient = l_recipient
i_express = 'X' .
* i_copy = ' '
* i_blind_copy = ' '
* i_no_forward = ' '.
ENDLOOP.
**-->Trigger E-Mail immediately*
* IF fp_send_all EQ 'X'.
* l_send_request->set_send_immediately( 'X' ).
* ENDIF.
CALL METHOD l_send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING result = l_v_sent_to_all ).
BREAK TARK.
IF l_v_sent_to_all = 'X'.
MESSAGE i000 .
ENDIF.
COMMIT WORK.
CATCH cx_document_bcs INTO l_bcs_exception.
CATCH cx_send_req_bcs INTO l_send_exception.
CATCH cx_address_bcs INTO l_addr_exception.
CATCH cx_bcs INTO l_exp.
ENDTRY.
thanks in advance
rahulEvery time when i choose other network or dongle to send those mails it gets sent.
As per the description, seems it's an issue related to this specific network. Probably, they've adjusted their security policy, like blocked some port numbers, etc.
You might need to contact the support of your ISP to confirm what SMTP settings you need. Check port number, and security settings.
By the way, this is the forum to discuss questions and feedback for Windows-based Microsoft Office client. Since your query is directly related to
Office for mac, I would suggest you to post in the forum of
Office for Mac, where you can get more experienced responses:
http://answers.microsoft.com/en-us/mac/forum/macoffice2011?tab=Threads
The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.
Regards,
Ethan Hua
TechNet Community Support
It's recommended to download and install
Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
programs. -
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:\ . -
Authentication Failed Exception while reading mail using POP
Hi,
I am using POP3 for reading mails from mail id. When I try to read the mail from Microsoft Exchange server 2007, it is a success. But same code is giving "Authentication Failed Exception" with Microsoft Exchange server 2010.
One more difference, I figured out. Microsoft Exchange server 2007 is having NTLM as LoginType and code works fine with it. Where as Microsoft Exchange server 2010 is having TLS as LoginType and code is giving "Authentication Failed Exception".
Line of code which is giving exception is...
store = session.getStore(providerPOP3);
store.connect(host, user, password); //throws exception
Please advice how this code can work with Microsoft Exchange server 2010 having TLS as LoginType.
Regards,Thanks for your reply.
Yes, I am using javamail 1.4.3. My code is working fine with Exchange server 2007 having NTLM.
But when I changed the credentials as per mail id configured on Exchange Server 2010 having TLS support, it did not work. Can you please help what code change would be required to read mails from mail id configured on Exchage Server 2010 having TLS support.
Sorry, if my point seems not understandable as I am as new with these terminologies (mail server and all) as baby with world. :)
Thanks for supprt. -
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"); -
Problems while sending mail using java mail
hi all,
the following are the errors i get while sending a mail from my smtp local host-
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class SendEmail
public static void main(String[] args)
System.out.println(args.length);
if (args.length != 6)
System.out.println("usage: sendmessage <to> <from> <smtphost> <true|false> <subject> <text>");
System.exit(1);System.out.println("jj"+args.length);
SendEmail m=new SendEmail();
m.SendMessage(args[0],args[1], args[2], args[3], args[4], args[5]);
public static String SendMessage(String emailto, String emailfrom, String smtphost, String emailmultipart, String msgSubject, String msgText)
boolean debug = false; // change to get more information
String msgText2 = "multipart message";
boolean sendmultipart = Boolean.valueOf(emailmultipart).booleanValue();
// set the host
Properties props = new Properties();
props.put("mail.smtp.host",smtphost);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.sendpartial", "true");
Authenticator loAuthenticator = new SMTPAuthenticator();
System.out.println("f");
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, loAuthenticator );
session.setDebug(debug);
try
// create a message
Message msg = new MimeMessage(session);
// set the from
InternetAddress from = new InternetAddress(emailfrom);
msg.setFrom(from);
InternetAddress[] address =
new InternetAddress(emailto)
//InternetAddress ad=new InternetAddress(session);
msg.setRecipients(Message.RecipientType.TO, address);
System.out.println("fc");
msg.setSubject(msgSubject);
System.out.println("fvf");
if(!sendmultipart)
// send a plain text message
msg.setContent(msgText, "text/plain");
System.out.println("fif");
else
System.out.println("felsd");
// send a multipart message// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setContent(msgText, "text/plain");
// create and fill the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
mbp2.setContent(msgText2, "text/plain");
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the Multipart to the message
msg.setContent(mp);
Transport transport = session.getTransport("smtp");
transport.connect(smtphost,"[email protected]","xyz");
msg.saveChanges();
System.out.println("fconn");
//transport.sendMessage(msg,msg.getAllRecipients());
transport.sendMessage(msg,msg.getAllRecipients());
transport.close();
//Transport.send(msg);
catch(MessagingException mex)
mex.printStackTrace();
return "Email sent to " + emailto;
class SMTPAuthenticator extends Authenticator
public PasswordAuthentication getPasswordAuthentication()
String username = "[email protected]";
String password = "xyz";
return new PasswordAuthentication(username, password);
i dont understand what the problem is..inspite of having the right code..
i guess some firewall problem..
can somebody help me please..il be highly obliged..thanks..hi all,
the following are the errors i get while sending a mail from my smtp local host-
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class SendEmail
public static void main(String[] args)
System.out.println(args.length);
if (args.length != 6)
System.out.println("usage: sendmessage <to> <from> <smtphost> <true|false> <subject> <text>");
System.exit(1);System.out.println("jj"+args.length);
SendEmail m=new SendEmail();
m.SendMessage(args[0],args[1], args[2], args[3], args[4], args[5]);
public static String SendMessage(String emailto, String emailfrom, String smtphost, String emailmultipart, String msgSubject, String msgText)
boolean debug = false; // change to get more information
String msgText2 = "multipart message";
boolean sendmultipart = Boolean.valueOf(emailmultipart).booleanValue();
// set the host
Properties props = new Properties();
props.put("mail.smtp.host",smtphost);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.sendpartial", "true");
Authenticator loAuthenticator = new SMTPAuthenticator();
System.out.println("f");
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, loAuthenticator );
session.setDebug(debug);
try
// create a message
Message msg = new MimeMessage(session);
// set the from
InternetAddress from = new InternetAddress(emailfrom);
msg.setFrom(from);
InternetAddress[] address =
new InternetAddress(emailto)
//InternetAddress ad=new InternetAddress(session);
msg.setRecipients(Message.RecipientType.TO, address);
System.out.println("fc");
msg.setSubject(msgSubject);
System.out.println("fvf");
if(!sendmultipart)
// send a plain text message
msg.setContent(msgText, "text/plain");
System.out.println("fif");
else
System.out.println("felsd");
// send a multipart message// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setContent(msgText, "text/plain");
// create and fill the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
mbp2.setContent(msgText2, "text/plain");
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the Multipart to the message
msg.setContent(mp);
Transport transport = session.getTransport("smtp");
transport.connect(smtphost,"[email protected]","xyz");
msg.saveChanges();
System.out.println("fconn");
//transport.sendMessage(msg,msg.getAllRecipients());
transport.sendMessage(msg,msg.getAllRecipients());
transport.close();
//Transport.send(msg);
catch(MessagingException mex)
mex.printStackTrace();
return "Email sent to " + emailto;
class SMTPAuthenticator extends Authenticator
public PasswordAuthentication getPasswordAuthentication()
String username = "[email protected]";
String password = "xyz";
return new PasswordAuthentication(username, password);
i dont understand what the problem is..inspite of having the right code..
i guess some firewall problem..
can somebody help me please..il be highly obliged..thanks.. -
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.
-
Getting error while sending mail through javamail api
I can able to compile the following code successfully but while executing it showing the error
C:\Program Files\Java\javamail-1.4\demo>java msgsend -o [email protected] -M 203.112.158.188 [email protected]
Exception in thread "main" java.lang.NoClassDefFoundError: msgsend
import java.io.*;
import java.net.InetAddress;
import java.util.Properties;
import java.util.Date;
import javax.mail.*;
import javax.mail.internet.*;
public class msgsend {
public static void main(String[] argv) {
String to, subject = null, from = null,
cc = null, bcc = null, url = null;
String mailhost = "null";
String mailer = "msgsend";
String file = null;
String protocol = null, host = null, user = null, password = null;
String record = null; // name of folder in which to record mail
boolean debug = false;
BufferedReader in =
new BufferedReader(new InputStreamReader(System.in));
int optind;
for (optind = 0; optind < argv.length; optind++) {
if (argv[optind].equals("-T")) {
protocol = argv[++optind];
} else if (argv[optind].equals("-H")) {
host = argv[++optind];
} else if (argv[optind].equals("-U")) {
user = argv[++optind];
} else if (argv[optind].equals("-P")) {
password = argv[++optind];
} else if (argv[optind].equals("-M")) {
mailhost = argv[++optind];
} else if (argv[optind].equals("-f")) {
record = argv[++optind];
} else if (argv[optind].equals("-a")) {
file = argv[++optind];
} else if (argv[optind].equals("-s")) {
subject = argv[++optind];
} else if (argv[optind].equals("-o")) { // originator
from = argv[++optind];
} else if (argv[optind].equals("-c")) {
cc = argv[++optind];
} else if (argv[optind].equals("-b")) {
bcc = argv[++optind];
} else if (argv[optind].equals("-L")) {
url = argv[++optind];
} else if (argv[optind].equals("-d")) {
debug = true;
} else if (argv[optind].equals("--")) {
optind++;
break;
} else if (argv[optind].startsWith("-")) {
System.out.println(
"Usage: msgsend [[-L store-url] | [-T prot] [-H host] [-U user] [-P passwd]]");
System.out.println(
"\t[-s subject] [-o from-address] [-c cc-addresses] [-b bcc-addresses]");
System.out.println(
"\t[-f record-mailbox] [-M transport-host] [-a attach-file] [-d] [address]");
System.exit(1);
} else {
break;
try {
if (optind < argv.length) {
// XXX - concatenate all remaining arguments
to = argv[optind];
System.out.println("To: " + to);
} else {
System.out.print("To: ");
System.out.flush();
to = in.readLine();
if (subject == null) {
System.out.print("Subject: ");
System.out.flush();
subject = in.readLine();
} else {
System.out.println("Subject: " + subject);
Properties props = System.getProperties();
// XXX - could use Session.getTransport() and Transport.connect()
// XXX - assume we're using SMTP
if (mailhost != null)
props.put("mail.smtp.host", mailhost);
// Get a Session object
Session session = Session.getInstance(props, null);
if (debug)
session.setDebug(true);
// construct the message
Message msg = new MimeMessage(session);
if (from != null)
msg.setFrom(new InternetAddress(from));
else
msg.setFrom();
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to, false));
if (cc != null)
msg.setRecipients(Message.RecipientType.CC,
InternetAddress.parse(cc, false));
if (bcc != null)
msg.setRecipients(Message.RecipientType.BCC,
InternetAddress.parse(bcc, false));
msg.setSubject(subject);
String text = collect(in);
if (file != null) {
// Attach the specified file.
// We need a multipart message to hold the attachment.
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(text);
MimeBodyPart mbp2 = new MimeBodyPart();
mbp2.attachFile(file);
MimeMultipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
msg.setContent(mp);
} else {
// If the desired charset is known, you can use
// setText(text, charset)
msg.setText(text);
msg.setHeader("X-Mailer", mailer);
msg.setSentDate(new Date());
// send the thing off
Transport.send(msg);
System.out.println("\nMail was sent successfully.");
// Keep a copy, if requested.
if (record != null) {
// Get a Store object
Store store = null;
if (url != null) {
URLName urln = new URLName(url);
store = session.getStore(urln);
store.connect();
} else {
if (protocol != null)
store = session.getStore(protocol);
else
store = session.getStore();
// Connect
if (host != null || user != null || password != null)
store.connect(host, user, password);
else
store.connect();
// Get record Folder. Create if it does not exist.
Folder folder = store.getFolder(record);
if (folder == null) {
System.err.println("Can't get record folder.");
System.exit(1);
if (!folder.exists())
folder.create(Folder.HOLDS_MESSAGES);
Message[] msgs = new Message[1];
msgs[0] = msg;
folder.appendMessages(msgs);
System.out.println("Mail was recorded successfully.");
} catch (Exception e) {
e.printStackTrace();
public static String collect(BufferedReader in) throws IOException {
String line;
StringBuffer sb = new StringBuffer();
while ((line = in.readLine()) != null) {
sb.append(line);
sb.append("\n");
return sb.toString();
So please help me to resolve that error.The directory that contains msgsend.class (usually the current directory)
is not in your CLASSPATH setting. Be sure that "." is included as one of the
entries in CLASSPATH. -
Hi I am getting javax.mail.sendFailedException: InvalidAddreses
nested exception is class com.sun.mail.smtp.SMTPAddressFailedException:553 sorry that domain isn't in my list of allowed rcpthosts<#5.7.1>
Here my Program:
package com.fortune2win.mail;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
// Send a simple, single part, text/plain e-mail
public class SendMail {
public void sendMail(String TO,String secCode, String UserNumber){
// SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
String from = "[email protected]";
// SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
String host = "207.234.145.236";
// Create properties, get Session
Properties props = new Properties();
props.put("mail.transport.protocol","smtp");
// If using static Transport.send(),
// need to specify which host to send it to
props.put("mail.smtp.host", host);
// To see what is going on behind the scene
props.put("mail.debug", "true");
Session session = Session.getDefaultInstance(props);
try {
// Instantiatee a message
Message msg = new MimeMessage(session);
//Set message attributes
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] address = {new InternetAddress(TO)};
msg.setRecipients(Message.RecipientType.TO,address);
msg.setSubject("F2W Player's Intimation");
// Set message content
msg.setText("Thank You for playing F2W online game.\n \n"+
"CONGRATULATIONS\n \n "+
"Your Number:" UserNumber""+"is a valid entry. \n"+
"Your Security Code:"+""+secCode+""+"\n" +
"You are entitled to claim the prize only if you produce a print of this mail."+
"\n Click www.fortune2win.com/home_index.jsp for prizedetails.\n");
//Send the message
Transport.send(msg);
catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well
mex.printStackTrace();
//End of class
Plz it urgent...Help meHi thanks for the reply.
But the TO addreass I specified in the argumentlist. that is outside the program.
But the mails are going to with in the same host that is under given host address(XXX.XXX.XXX.XXX) .
Wht I mean is..mails are going with in my company...but outside mails are not going...like yahoo/gmail..etc..
plz help .
TO address i am taking from Form textbox
Regards
Varma
Maybe you are looking for
-
Material Consumtpion restriction by Vendor
Dear All, I am working with a pharma company where this unique requirement came out. Same raw material will be bought from Vendor A (M1) and Vendor B(M2) as well. Since these are pharma specific materials, they cannot even combine these two while con
-
A pdf with two forms to be saved out separately...
I have a request from my customers to create a single PDF (price list) that also includes two separate forms. They want to be able to fill out each form within the single price list PDF document, but save each of the forms out separately from each ot
-
Client Authentication based on source IP
Hi All, I am using a CSS 11503 to load balance 2 intranet web servers. Currently, the web server checks for the source IP and if it is from the internet, it authenticates the users using LDAP. Now, application folks are asking me if CSS could prompt
-
Mail.app + SMTP oddity...
Hello all, Several users at the college I work for are reporting a sudden breakdown of SMTP services using Mail.app under 10.4.x. All clients were previously functioning, but suddenly stopped being able to send (they get the "could not send from this
-
Hi to all. I'm trying to change the name that the dock shows when my java app is running. I have read all this , but the problem that I have is that I want to do it into my code and not from the terminal line. I want to do this, from my code. -Xdock: