Hızlı Konu Açma

Hızlı Konu Açmak için tıklayınız.

Son Mesajlar

Konulardaki Son Mesajlar

Reklam

Forumda Reklam Vermek İçin Bize Ulaşın

Java ile e-posta yollama kodu (activation.jar ve mail.jar gerektirir)

BlackKey

Üye
Fenerbahçe
Kayıtlı Üye
Katılım
12 Eylül 2014
Mesajlar
167
Tepkime puanı
0
Puanları
0
Kod:
[B]import javax.mail.*;[/B][COLOR=YellowGreen][B]import javax.mail.internet.*;
import java.util.*;
import javax.activation.*;
import java.io.*;
public class SimpleSender
{
       public static **** main(String args[])
       {
              try
              {
                     String smtpServer=args[0];
                     String to=args[1];
                     String from=args[2];
                     String body=args[3];
                     send(smtpServer, to, from,body);
              }
              catch (Exception ex)
              {
                System.out.println("Usage :\njava SimpleSender server to from body");
              }
        System.exit(0);
       }
 
     public static **** send(String smtpServer, String to, String from, String body)
       {
             try
              {
                Properties props = System.getProperties();
                props.put("mail.smtp.host", smtpServer);
                Session session = Session.getDefaultInstance(props, null);
                MimeMessage msg = new MimeMessage(session);
                msg.setFrom(new InternetAddress(from));
                msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to, false));
                msg.setSubject("Test Mail thru java");
               msg.setContent(body,"text/plain");
                msg.setSentDate(new Date());
                Transport.send(msg);
                System.out.println("Message sent OK.");
         }
         catch (Exception ex)
         {
                ex.printStackTrace();
         }
}
 
  [/B][/COLOR][B]}[/B]
 

Users Who Are Viewing This Konu (Users: 0, Guests: 1)

Üst