ලේසියෙන්ම හොයාගන්න මෙතනින්

Java Desktop Application එකකින් GMail, Yahoo හරහා Email යවමු.

මේ වගේම වැඩක් කලින් C# වලින් Desktop Application සඳහා කළා ඔයාලට මතක ඇති. මෙන්න Java වලින් ඒ වැඩේ කරන හැටි. මෙතැනදී Email එක යවන කෙනාගේ email එක Yahoo ද, GMail ද කියන එක program එකෙන් auto detect කරගන්න විදියටයි හැදුවේ. ඒ අනුව අදාල email server එක හදුනාගෙන email එක send වෙනවා. ඔයාලත් අත්හදා බලන්න. සමහරවිට ඔයාලගේ client කෙනෙකුට කරන software එකකට මෙහෙම දෙයක් උවමනා වෙන්න පුළුවන්.
C# වලින් ඕන අයට, මේක අලුතින්ම දකින අයට,
C# වලින් Gmail හරහා Email යවන හැටි මෙතනින් බලන්න.
http://kohomaharigodayamu.blogspot.com/2012/06/c-application-gmail-email.html
C# වලින් Yahoo හරහා Email යවන හැටි මෙතනින් බලන්න.
http://kohomaharigodayamu.blogspot.com/2012/06/c-application-yahoo-mail-email.html

මේ post එකත් එක්කම මේකේ source code සහ මේ සඳහා උවමනා කරන jar library file ටිකත් ලබාදෙනවා.
කරලා තියෙන code තේරුම් ගැනීම ඔබට බාරයි. නොතේරෙන තැනක් තිබුනොත් අහන්න. අපේ හුගක් අයට code එකක් තේරුම් ගන්න, programming language ඉගෙන ගන්න හිතෙන්නේ Viva එකක්, Assignment එකක්, Exam එකක් ළඟ එනකොට විතරනේ. 

Send Email via GMail, Yahoo Mail Java SE Software Download
contains exe and jar files including libraries
http://www.mediafire.com/?vnqj088cv208eed

Send Email via GMail, Yahoo Mail Java SE Source Code Download
contains NetBeans Project with all stuff (images, libraries, source codes)
http://www.mediafire.com/?m2bjimd0iardxrz

private void sendActionPerformed(java.awt.event.ActionEvent evt) {                                    
        final String from = fromEmail.getText();
        String to = toEmail.getText();
        final String password = new String(fromEmailPassword.getPassword());
        String _subject = subject.getText();
        String body = emailBody.getText();
        InternetAddress emailFrom = null;
        InternetAddress emailTo = null;
        try {
            emailFrom = new InternetAddress(from);
            emailTo = new InternetAddress(to);
            emailFrom.validate();           
            emailTo.validate();
            if(from.contains("gmail")){
                Properties props = new Properties();
                props.put("mail.smtp.auth", "true");
                props.put("mail.smtp.starttls.enable", "true");
                props.put("mail.smtp.host", "smtp.gmail.com");
                props.put("mail.smtp.port", "587");
                Session session = Session.getInstance(props,
                new javax.mail.Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication(from, password);
                    }
                });
                Message message = new MimeMessage(session);
                message.setFrom(emailFrom);
                message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to));
                message.setSubject(_subject);
                message.setText(body);
                Transport.send(message);
                JOptionPane.showMessageDialog(this, "Email Successfully Sent");
            }else if(from.contains("yahoo")){
                Properties props = new Properties();
                props.put("mail.smtp.host", "smtp.mail.yahoo.com");
                props.put("mail.stmp.user", from);
                props.put("mail.smtp.auth", "true");
                props.put("mail.smtp.starttls.enable", "true");
                props.put("mail.smtp.password", password);
                Session session = Session.getDefaultInstance(props, new Authenticator() {
                @Override
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(from, password);
                }
                });
                MimeMessage msg = new MimeMessage(session);
                msg.setFrom(new InternetAddress(from));
                msg.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(to));
                msg.setSubject(_subject);
                msg.setText("yahoo program working...!");
                Transport transport = session.getTransport("smtp");
                transport.send(msg);
                JOptionPane.showMessageDialog(this, "Email Successfully Sent");
            }
        } catch (MessagingException ex) {
            JOptionPane.showMessageDialog(this, "Something Wrong. Check Both Emails Entered Correctly or Your Internet Connection");
        }
}

4 comments :

  1. නියමයි .....
    දිගටම කරන් පලයන්
    එළ.......... :)

    ReplyDelete
  2. නියම, හොඳ වැඩක් ඔයා මේ කරන්නේ.
    email app එක හොඳට වැඩ කරනවා. මම හිතුවෙ නැහැ මෙච්චර ලේසී කියල මේ app 1 හදා ගන්න.
    අනිත් අයට මේ ඔයාගෙ දැනුම බෙදා දෙන එකට ගොඩක් ස්තූතියි! දිගටම කරගෙන යන්න. අපිට පුලුවන් help 1k අපිත් දෙන්නම්.

    ReplyDelete
  3. මට help 1k ඕනේ,
    මම සිංහල unicode convert java app 1k හදනවා.
    ඒකෙ JTextArea හැම අකුරක්ම හොඳට පෙන්නනවා. නමුත් යංශය සහිත අකුරු විතරක්
    පෙන්වන්නේ වෙන වෙනම( උදා:- "ක්‍යෝ" පෙන්නනේ "කේයෝ" විදිහට).
    මම ඊට පසසේ AWT TextArea 1 ක display කරහම ඔක්කොම අකුරු හරියටම පෙන්නනවා.නමුත්, හැම අකුරකම ව්‍යංජන හා ස්වර අකුරු සම්බන්ධව තිබුනත්, ව්‍යංජන හා ස්වර අකුරු අතර හිඩැස් පෙන්නනවා.
    මේ ප්‍රශ්න 2න් 2ම හෝ 1ක් වත් විසඳගන්න උදව් කරන්න හැකි ඉක්මනට.
    ස්තූතියි.
    මම ෂෙහාන්.

    ReplyDelete
    Replies
    1. ඔයාගේ Operating System එක මොකක්ද ?
      මම Java Text Boxes, Text Area වල සිංහල type කරලා තියේ. එත් එහෙම දෙයක් වෙලානම් නැහැ,

      Delete