Jun 04
Java’da mail atabilmemiz için bize smtp servisi sağlayan bir mail sunucumuz olmalı. Ben varsayım olarak “mail.sunucu.com” adresini benim mail sunucum olarak kabul ediyorum.
try { Properties props = new Properties(); props.put("mail.smtp.host", "mail.sunucu.com"); props.put("mail.smtp.auth","true"); // mail sunucusundaki mail adresiniz props.put("mail.smtp.user", "test@sunucu.com"); props.put("mail.smtp.port", "25"); props.put("mail.debug", "true"); Session session = Session.getDefaultInstance(props); MimeMessage msg = new MimeMessage(session); // mailin gönderilen kısmında yazan mail adresi msg.setFrom(new InternetAddress("test@sunucu.com")); InternetAddress addressTo = null; // mail alacak olan kişinin mail adresi addressTo = new InternetAddress("erol@javaci.net"); msg.setRecipient(javax.mail.Message.RecipientType.TO, addressTo); // mail başlığınız msg.setSubject("Benim Konum"); // mail konunuz msg.setContent("Benim Mesajım", "text/html; charset=iso-8859-9"); Transport t = session.getTransport("smtp"); // mail sunucusundaki mail adresiniz ve şifreniz t.connect("test@sunucu.com", "şifre"); t.sendMessage(msg, msg.getAllRecipients()); t.close(); } catch(Exception exc) { exc.printStackTrace(); }
Mail gönderebilmemiz için gerekli Java Mail API’sini proje dosyasına eklememiz gerekecek.
Java Mail API (364.2 KiB, 91 hits)

Son Yorumlar