Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #13378 > unrolled thread

java mail api

Started byakhil srivastava <akhil.srivastava000@gmail.com>
First post2012-04-03 15:57 -0700
Last post2012-04-04 23:40 +0000
Articles 4 — 4 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  java mail api akhil srivastava <akhil.srivastava000@gmail.com> - 2012-04-03 15:57 -0700
    Re: java mail api Roedy Green <see_website@mindprod.com.invalid> - 2012-04-04 14:23 -0700
    Re: java mail api Thufir <hawat.thufir@gmail.com> - 2012-04-04 13:27 -0700
      Re: java mail api Martin Gregorie <martin@address-in-sig.invalid> - 2012-04-04 23:40 +0000

#13378 — java mail api

Fromakhil srivastava <akhil.srivastava000@gmail.com>
Date2012-04-03 15:57 -0700
Subjectjava mail api
Message-ID<5b98a9f3-13ce-428d-8ffb-0cccc30e1769@px4g2000pbc.googlegroups.com>
i m trying sending mail with thia code ingmail code running success
fully but with rediffmail or yahoo it cannot run plzz help me

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public class mail1
{
         String  d_email = "akhil.sri@tgmail.com",
            d_password = "im*******",
            d_host = "smtp.gmail.com",
            d_port  = "587",
            m_to = "akhil_4u47@rediffmail.com",
            m_subject = "Testing",
            m_text = "Hey, this is the testing email using
smtp.gmail.com.";
    public static void main(String[] args)
    {
                String[] to={"akhil_4u47@rediffmail.com"};
              //  String[] cc={"XXX@yahoo.com"};
               // String[] bcc={"XXX@yahoo.com"};
                //This is for google
                        mail1.sendMail("akhil.sri@technolife.in",
                                "KB*!O^L7",
                                "smtp.gmail.com,
                                "587",
                                "true",
                                "true",
                                true,

                               "javax.net.ssl.SSLSocketFactory",
                               "false",
                               to,
                                "hiiiiiiiiiii",
                                "hiii this is akhil sening mail via
smtp and java mail api");
    }

        public synchronized static boolean sendMail(
                String userName,
                String passWord,
                String host,
                String port,
                String starttls,
                String auth,
                boolean debug,
                String socketFactoryClass,
                String fallback,
                String[] to,
                String subject,
                String text){
                Properties props = new Properties();
                //Properties props=System.getProperties();
        props.put("mail.smtp.user", userName);
        props.put("mail.smtp.host", host);
                if(!"".equals(port))
        props.put("mail.smtp.port", port);
                if(!"".equals(starttls))
        props.put("mail.smtp.starttls.enable",starttls);
        props.put("mail.smtp.auth", auth);
                if(debug){
                props.put("mail.smtp.debug", "true");
                }else{
                props.put("mail.smtp.debug", "false");
                }
                if(!"".equals(port))
        props.put("mail.smtp.socketFactory.port", port);
                if(!"".equals(socketFactoryClass))
        props.put("mail.smtp.socketFactory.class",socketFactoryClass);
                if(!"".equals(fallback))
        props.put("mail.smtp.socketFactory.fallback", fallback);
            System.out.println("properties");
        try
        {
                        Session session =
Session.getDefaultInstance(props, null);
            session.setDebug(debug);
            MimeMessage msg = new MimeMessage(session);
            msg.setText(text);
            msg.setSubject(subject);
            msg.setFrom(new
InternetAddress("akhil_4u47@rediffmail.com"));
                        for(int i=0;i<to.length;i++){
            msg.addRecipient(Message.RecipientType.TO, new
InternetAddress(to[i]));
                        }
//                        for(int i=0;i<cc.length;i++){
//            msg.addRecipient(Message.RecipientType.CC, new
InternetAddress(cc[i]));
//                        }
//                        for(int i=0;i<bcc.length;i++){
//            msg.addRecipient(Message.RecipientType.BCC, new
InternetAddress(bcc[i]));
//                        }
            msg.saveChanges();
                        Transport transport =
session.getTransport("smtp");
                        transport.connect(host, userName, passWord);
                        transport.sendMessage(msg,
msg.getAllRecipients());
                        transport.close();
                        return true;
        }
        catch (Exception mex)
        {
            //mex.printStackTrace();
            System.out.println("error"+mex);
                        return false;
        }
        }

}

[toc] | [next] | [standalone]


#13391

FromRoedy Green <see_website@mindprod.com.invalid>
Date2012-04-04 14:23 -0700
Message-ID<1repn75q2406f974u5gvgiqdre6km2dqgd@4ax.com>
In reply to#13378
I have written a javamail app that does work.  You can have a look to
see the basic skeleton.

https://wush.net/websvn/mindprod/listing.php?repname=mindprod&path=%2Fcom%2Fmindprod%2Fbulk%2F


On Tue, 3 Apr 2012 15:57:11 -0700 (PDT), akhil srivastava
<akhil.srivastava000@gmail.com> wrote, quoted or indirectly quoted
someone who said :

>i m trying sending mail with thia code ingmail code running success
>fully but with rediffmail or yahoo it cannot run plzz help me
>
>import javax.mail.*;
>import javax.mail.internet.*;
>import java.util.*;
>
>public class mail1
>{
>         String  d_email = "akhil.sri@tgmail.com",
>            d_password = "im*******",
>            d_host = "smtp.gmail.com",
>            d_port  = "587",
>            m_to = "akhil_4u47@rediffmail.com",
>            m_subject = "Testing",
>            m_text = "Hey, this is the testing email using
>smtp.gmail.com.";
>    public static void main(String[] args)
>    {
>                String[] to={"akhil_4u47@rediffmail.com"};
>              //  String[] cc={"XXX@yahoo.com"};
>               // String[] bcc={"XXX@yahoo.com"};
>                //This is for google
>                        mail1.sendMail("akhil.sri@technolife.in",
>                                "KB*!O^L7",
>                                "smtp.gmail.com,
>                                "587",
>                                "true",
>                                "true",
>                                true,
>
>                               "javax.net.ssl.SSLSocketFactory",
>                               "false",
>                               to,
>                                "hiiiiiiiiiii",
>                                "hiii this is akhil sening mail via
>smtp and java mail api");
>    }
>
>        public synchronized static boolean sendMail(
>                String userName,
>                String passWord,
>                String host,
>                String port,
>                String starttls,
>                String auth,
>                boolean debug,
>                String socketFactoryClass,
>                String fallback,
>                String[] to,
>                String subject,
>                String text){
>                Properties props = new Properties();
>                //Properties props=System.getProperties();
>        props.put("mail.smtp.user", userName);
>        props.put("mail.smtp.host", host);
>                if(!"".equals(port))
>        props.put("mail.smtp.port", port);
>                if(!"".equals(starttls))
>        props.put("mail.smtp.starttls.enable",starttls);
>        props.put("mail.smtp.auth", auth);
>                if(debug){
>                props.put("mail.smtp.debug", "true");
>                }else{
>                props.put("mail.smtp.debug", "false");
>                }
>                if(!"".equals(port))
>        props.put("mail.smtp.socketFactory.port", port);
>                if(!"".equals(socketFactoryClass))
>        props.put("mail.smtp.socketFactory.class",socketFactoryClass);
>                if(!"".equals(fallback))
>        props.put("mail.smtp.socketFactory.fallback", fallback);
>            System.out.println("properties");
>        try
>        {
>                        Session session =
>Session.getDefaultInstance(props, null);
>            session.setDebug(debug);
>            MimeMessage msg = new MimeMessage(session);
>            msg.setText(text);
>            msg.setSubject(subject);
>            msg.setFrom(new
>InternetAddress("akhil_4u47@rediffmail.com"));
>                        for(int i=0;i<to.length;i++){
>            msg.addRecipient(Message.RecipientType.TO, new
>InternetAddress(to[i]));
>                        }
>//                        for(int i=0;i<cc.length;i++){
>//            msg.addRecipient(Message.RecipientType.CC, new
>InternetAddress(cc[i]));
>//                        }
>//                        for(int i=0;i<bcc.length;i++){
>//            msg.addRecipient(Message.RecipientType.BCC, new
>InternetAddress(bcc[i]));
>//                        }
>            msg.saveChanges();
>                        Transport transport =
>session.getTransport("smtp");
>                        transport.connect(host, userName, passWord);
>                        transport.sendMessage(msg,
>msg.getAllRecipients());
>                        transport.close();
>                        return true;
>        }
>        catch (Exception mex)
>        {
>            //mex.printStackTrace();
>            System.out.println("error"+mex);
>                        return false;
>        }
>        }
>
>}
-- 
Roedy Green Canadian Mind Products
http://mindprod.com
When you were a child, if you did your own experiment
to see if it was better to put to cocoa into your cup first
or the hot milk first, then you likely have the programmer gene..

[toc] | [prev] | [next] | [standalone]


#13398

FromThufir <hawat.thufir@gmail.com>
Date2012-04-04 13:27 -0700
Message-ID<6enu49-jf2.ln1@dur.bounceme.net>
In reply to#13378
On Tue, 03 Apr 2012 15:57:11 -0700, akhil srivastava wrote:

> i m trying sending mail with thia code ingmail code running success
> fully but with rediffmail or yahoo it cannot run plzz help me

Does it build?  When it runs, what's the error?

[toc] | [prev] | [next] | [standalone]


#13400

FromMartin Gregorie <martin@address-in-sig.invalid>
Date2012-04-04 23:40 +0000
Message-ID<jlim4k$r7k$2@localhost.localdomain>
In reply to#13398
On Wed, 04 Apr 2012 13:27:18 -0700, Thufir wrote:

> On Tue, 03 Apr 2012 15:57:11 -0700, akhil srivastava wrote:
> 
>> i m trying sending mail with thia code ingmail code running success
>> fully but with rediffmail or yahoo it cannot run plzz help me
> 
> Does it build?  When it runs, what's the error?

When it runs, what is output if you turn tracing on?



-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web