« Return to Thread: How to send smtp mail

Re: How to send smtp mail

by HandyGeek :: Rate this Message:

Reply to Author | View in Thread

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hello Augustine,
In addition to David Beer's suggestion, try this:
First, use a fully qualified mailhost name, for example mine is:
String mailhost = "ibxxxhub.xx.usbr.gov";          // SMTP server

Second, once you connect to the mailhost, it likely will require a valid login.  I use my personal email userid & password for mailhost authentication:
String user = "dthompson";                          // user ID
String password = "myPaSsWord";                       // password

HTH, David

 -------------- Original message ----------------------
From: David Beer <david.m.beer@...>

> Hi
>
> You may find the following link useful. It describes how you can send email
> using java
> http://www.builderau.com.au/program/java/soa/Sending-e-mail-in-Java-There-s-more
> -than-one-way/0,339024620,339222642,00.htm
>
> Most likely your issue is that your smtp will not allow you to send un
> authorised, the web page does give an example on how to authentication when
> sending an email.
>
> Thanks
>
> David
>
> ----- Original Message ----
> From: Augustine Enang <Enang.Augustine@...>
> To: nbusers@...
> Sent: Wednesday, 9 April, 2008 9:43:33 AM
> Subject: [nbusers] How to send smtp mail
>
>  
> <!--
>  _filtered {font-family:"Cambria Math";panose-1:2 4 5 3 5 4 6 3 2 4;}
>  _filtered {font-family:Calibri;panose-1:2 15 5 2 2 2 4 3 2 4;}
>  _filtered {font-family:Tahoma;panose-1:2 11 6 4 3 5 4 4 2 4;}
> /* Style Definitions */
>  p.MsoNormal, li.MsoNormal, div.MsoNormal
>
> {margin:0in;margin-bottom:.0001pt;font-size:11.0pt;font-family:"Calibri",
> "sans-serif";}
> a:link, span.MsoHyperlink
> {color:blue;text-decoration:underline;}
> a:visited, span.MsoHyperlinkFollowed
> {color:purple;text-decoration:underline;}
> p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
> {margin:0in;margin-bottom:.0001pt;font-size:8.0pt;font-family:"Tahoma",
> "sans-serif";}
> span.EmailStyle17
> {font-family:"Calibri", "sans-serif";color:windowtext;}
> span.BalloonTextChar
> {font-family:"Tahoma", "sans-serif";}
> .MsoChpDefault
> {}
>  _filtered {margin:1.0in 1.0in 1.0in 1.0in;}
> div.Section1
> {}
> -->
> Hi,
>  Good day,
>  Am a netbeans fan and have been using it since 2005
>    
>  Current am working on a project that enable users log issues
> and to review all logged issues. The application is also meant to send email to
> the administrator whenever an issue is logged.
>  I encountered an error trying to send an email to the administrator.
> My mail server required authentication and it’s on a domain
>  The error I got is : cannot connect to smtp sever below is
> the code that should send the email
>    
>  CODE
>    
>  String to = "oteniya.olumide@...";    
> // to address
>          String from =
> "enang.augustine@..."; // from address
>          String
> emailSubject = theSubject;  // the subject line
>          String
> emailMessage =
> theMessage;                
> // the body of the message
>          String
> mailhost = "172.16.10.132"; // SMTP server
>          String user =
> "acb";                
> // user ID
>          String
> password =
> "password";            
> // password
>                                  //
> password
>          boolean auth =
> true;
>          boolean ssl =
> false;
>          Properties
> props = System.getProperties();
>          
>          if (mailhost
> != null) {
>            
> props.put("mail.smtp.host", mailhost);
>          }
>          if (auth) {
>            
> props.put("mail.smtp.auth", "true");
>          }
>          // Get a
> Session object
>        
> javax.mail.Session session = javax.mail.Session.getInstance(props, null);
>    
>          // Construct
> the message
>        
> javax.mail.Message msg = new MimeMessage(session);
>          
>          try {
>            
> // Set message details
>            
> msg.setFrom(new InternetAddress(from));
>            
> //msg.setRecipient(javax.mail.Message.RecipientType.TO, arg1)
>            
> msg.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));
>            
> msg.setSubject(emailSubject);
>            
> msg.setSentDate(new Date());
>            
> msg.setText(emailMessage);
>            
>
>            
> // Send the thing off
>            
> SMTPTransport t = (SMTPTransport)session.getTransport(ssl ? "smtps" :
> "smtp");
>            
> try {
>                  if
> (auth) {
>                    
> t.connect(mailhost, user, password);
>                
> } else {
>                    
> t.connect();
>                
> }
>                
> t.sendMessage(msg, msg.getAllRecipients());
>            
> } finally {
>                
>  t.close();
>            
> }
>            
> log("Mail was sent successfully.");
>          } catch
> (Exception e) {
>            
> if (e instanceof SendFailedException) {
>                
> MessagingException sfe = (MessagingException)e;
>                
> if (sfe instanceof SMTPSendFailedException) {
>                    
> SMTPSendFailedException ssfe = (SMTPSendFailedException)sfe;
>                    
> log("Smtp_Send_Failed:");
>                
> }
>                
> Exception ne;
>                                                                  while
> ((ne = sfe.getNextException()) != null && ne instanceof
> MessagingException) {
>                    
> sfe = (MessagingException)ne;
>                    
> if (sfe instanceof SMTPAddressFailedException) {
>                        
> SMTPAddressFailedException ssfe = (SMTPAddressFailedException)sfe;
>                        
> log("Address failed:");
>                        
> log(ssfe.toString());
>                        
> log("  Address: " + ssfe.getAddress());
>                        
> log("  Command: " + ssfe.getCommand());
>            
>              log("
> Return Code: " + ssfe.getReturnCode());
>                        
> log("  Response: " + ssfe.getMessage());
>                    
> } else if (sfe instanceof SMTPAddressSucceededException) {
>                        
> log("Address succeeded:");
>                        
> SMTPAddressSucceededException ssfe = (SMTPAddressSucceededException)sfe;
>                    
> }
>                                                                  }
>                    
> } else {
>                                                  log("Got
> Exception : " + e);          
>
>          }
>    
>  THIS IS THE ERROR I GOT
>    
>  Initializing Sun's JavaServer
> Faces implementation (1.2_04-b20-p03) for context '/querylogview'
>  PWC1412: WebModule[/querylogview]
> ServletContext.log():Got Exception : javax.mail.MessagingException: Could not
> connect to SMTP host: 172.16.10.132, port: 25;
>    nested exception is:
>        
> java.net.ConnectException: Connection refused: connect
>  
>    
>       I am working with netbeans 6.1  and the framework is
>        visual
>   web java server faces
>      
>    
>    
>  
>  Systems Development Unit
>  Information Technology Group
>  Intercontinental Bank Plc Nigeria
>  Plot 999c, Danmole street, Victoria Island, Lagos|
>  Phone +234 1 2773300|Cell +234 8059342751
>    
>  
>
>
>
>


Hi

You may find the following link useful. It describes how you can send email using java http://www.builderau.com.au/program/java/soa/Sending-e-mail-in-Java-There-s-more-than-one-way/0,339024620,339222642,00.htm

Most likely your issue is that your smtp will not allow you to send un authorised, the web page does give an example on how to authentication when sending an email.

Thanks

David

----- Original Message ----
From: Augustine Enang <Enang.Augustine@...>
To: nbusers@...
Sent: Wednesday, 9 April, 2008 9:43:33 AM
Subject: [nbusers] How to send smtp mail

Hi,

Good day,

Am a netbeans fan and have been using it since 2005

 

Current am working on a project that enable users log issues and to review all logged issues. The application is also meant to send email to the administrator whenever an issue is logged.

I encountered an error trying to send an email to the administrator. My mail server required authentication and it’s on a domain

The error I got is : cannot connect to smtp sever below is the code that should send the email

 

CODE

 

String to = "oteniya.olumide@...";     // to address

        String from = "enang.augustine@..."; // from address

        String emailSubject = theSubject;  // the subject line

        String emailMessage = theMessage;                  // the body of the message

        String mailhost = "172.16.10.132"; // SMTP server

        String user = "acb";                 // user ID

        String password = "password";              // password

                                // password

        boolean auth = true;

        boolean ssl = false;

        Properties props = System.getProperties();

       

        if (mailhost != null) {

            props.put("mail.smtp.host", mailhost);

        }

        if (auth) {

            props.put("mail.smtp.auth", "true");

        }

        // Get a Session object

        javax.mail.Session session = javax.mail.Session.getInstance(props, null);

  

        // Construct the message

        javax.mail.Message msg = new MimeMessage(session);

       

        try {

            // Set message details

            msg.setFrom(new InternetAddress(from));

            //msg.setRecipient(javax.mail.Message.RecipientType.TO, arg1)

            msg.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));

            msg.setSubject(emailSubject);

            msg.setSentDate(new Date());

            msg.setText(emailMessage);

           

            // Send the thing off

            SMTPTransport t = (SMTPTransport)session.getTransport(ssl ? "smtps" : "smtp");

            try {

                if (auth) {

                    t.connect(mailhost, user, password);

                } else {

                    t.connect();

                }

                t.sendMessage(msg, msg.getAllRecipients());

            } finally {

                t.close();

            }

            log("Mail was sent successfully.");

        } catch (Exception e) {

            if (e instanceof SendFailedException) {

                MessagingException sfe = (MessagingException)e;

                if (sfe instanceof SMTPSendFailedException) {

                    SMTPSendFailedException ssfe = (SMTPSendFailedException)sfe;

                    log("Smtp_Send_Failed:");

                }

                Exception ne;

                                                                while ((ne = sfe.getNextException()) != null && ne instanceof MessagingException) {

                    sfe = (MessagingException)ne;

                    if (sfe instanceof SMTPAddressFailedException) {

                        SMTPAddressFailedException ssfe = (SMTPAddressFailedException)sfe;

                        log("Address failed:");

                        log(ssfe.toString());

                        log("  Address: " + ssfe.getAddress());

                        log("  Command: " + ssfe.getCommand());

                        log("  Return Code: " + ssfe.getReturnCode());

                        log("  Response: " + ssfe.getMessage());

                    } else if (sfe instanceof SMTPAddressSucceededException) {

                        log("Address succeeded:");

                        SMTPAddressSucceededException ssfe = (SMTPAddressSucceededException)sfe;

                    }

                                                                }

                    } else {

                                                log("Got Exception : " + e);           

        }

 

THIS IS THE ERROR I GOT

 

Initializing Sun's JavaServer Faces implementation (1.2_04-b20-p03) for context '/querylogview'

PWC1412: WebModule[/querylogview] ServletContext.log():Got Exception : javax.mail.MessagingException: Could not connect to SMTP host: 172.16.10.132, port: 25;

  nested exception is:

        java.net.ConnectException: Connection refused: connect

 

I am working with netbeans 6.1  and the framework is

visual web java server faces

 

 

 

cid:image003.jpg@01C87AFA.EFA50080 

Systems Development Unit

Information Technology Group

Intercontinental Bank Plc Nigeria

Plot 999c, Danmole street, Victoria Island, Lagos|

Phone +234 1 2773300|Cell +234 8059342751 

 


 « Return to Thread: How to send smtp mail