Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Power Lifting Lever Belt
SkullVamp
Updated:
Yesterday at 10:32 PM
Ad icon
port.lk Domain for sale
Lankan-Tech
Updated:
Yesterday at 3:55 PM
Colombo
Kaduwela - Two Storey House for Sale
dilrasan
Updated:
Thursday at 2:23 PM
Ad icon
Wechat qr verification
Pawan2005
Updated:
Thursday at 1:28 AM
🚀 GOOGLE AI PRO 18 MONTHS ACTIVATION 🚀
sayuru bandara
Updated:
Wednesday at 5:34 PM
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Help
JAVA SWING EMAIL SENDING ...PLS HELP ME
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="NO_MeRcY" data-source="post: 12430083" data-attributes="member: 289641"><p>without GUI </p><p></p><p>[CODE]</p><p></p><p>import java.util.Properties;</p><p></p><p>import javax.mail.Message;</p><p>import javax.mail.MessagingException;</p><p>import javax.mail.Session;</p><p>import javax.mail.Transport;</p><p>import javax.mail.Message.RecipientType;</p><p>import javax.mail.internet.AddressException;</p><p>import javax.mail.internet.InternetAddress;</p><p>import javax.mail.internet.MimeMessage;</p><p></p><p>/**</p><p> *</p><p> * @author no_mercy</p><p> */</p><p>public class sendMail {</p><p></p><p> private String from;</p><p> private String to;</p><p> private String subject;</p><p></p><p> public String getFrom() {</p><p> return from;</p><p> }</p><p></p><p> public void setFrom(String from) {</p><p> this.from = from;</p><p> }</p><p></p><p> public String getSubject() {</p><p> return subject;</p><p> }</p><p></p><p> public void setSubject(String subject) {</p><p> this.subject = subject;</p><p> }</p><p></p><p> public String getText() {</p><p> return text;</p><p> }</p><p></p><p> public void setText(String text) {</p><p> this.text = text;</p><p> }</p><p></p><p> public String getTo() {</p><p> return to;</p><p> }</p><p></p><p> public void setTo(String to) {</p><p> this.to = to;</p><p> }</p><p> private String text;</p><p></p><p> public sendMail(String from, String to, String subject, String text) {</p><p> this.from = from;</p><p> this.to = to;</p><p> this.subject = subject;</p><p> this.text = text;</p><p> }</p><p></p><p> public void send() {</p><p></p><p> Properties props = new Properties();</p><p> props.put("mail.smtp.host", "192.168.xxx.xxx");</p><p> props.put("mail.protocol.port", 25);</p><p></p><p> Session mailSession = Session.getDefaultInstance(props);</p><p> Message simpleMessage = new MimeMessage(mailSession);</p><p></p><p> InternetAddress fromAddress = null;</p><p> InternetAddress toAddress = null;</p><p> try {</p><p> fromAddress = new InternetAddress(from);</p><p> toAddress = new InternetAddress(to);</p><p> } catch (AddressException e) {</p><p> e.printStackTrace();</p><p> }</p><p></p><p> try {</p><p> simpleMessage.setFrom(fromAddress);</p><p> simpleMessage.setRecipient(RecipientType.TO, toAddress);</p><p> simpleMessage.setSubject(subject);</p><p> simpleMessage.setText(text);</p><p></p><p> Transport.send(simpleMessage);</p><p> } catch (MessagingException e) {</p><p> e.printStackTrace();</p><p> }</p><p> }</p><p>}</p><p>[/CODE]</p><p></p><p></p><p>test client (GUI eka hada ganna)</p><p></p><p>[CODE]import email.sendMail;</p><p></p><p>/**</p><p> *</p><p> * @author no_mercy</p><p> */</p><p>public class TestClient {</p><p></p><p> public static void main(String args[]) {</p><p></p><p> String from = "no_mercy@xx.lk";</p><p> String to = "no_mercy@xx.lk";</p><p> String subject = "Test";</p><p> String message = "A test message";</p><p></p><p> sendMail sendMail = new sendMail(from, to, subject, message);</p><p> sendMail.send();</p><p> System.out.println("Email Sent");</p><p></p><p> }</p><p>}</p><p>[/CODE]</p><p></p><p></p><p>me tika run karala balapan. ubata therewi karnna one dey</p></blockquote><p></p>
[QUOTE="NO_MeRcY, post: 12430083, member: 289641"] without GUI [CODE] import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.Message.RecipientType; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; /** * * @author no_mercy */ public class sendMail { private String from; private String to; private String subject; public String getFrom() { return from; } public void setFrom(String from) { this.from = from; } public String getSubject() { return subject; } public void setSubject(String subject) { this.subject = subject; } public String getText() { return text; } public void setText(String text) { this.text = text; } public String getTo() { return to; } public void setTo(String to) { this.to = to; } private String text; public sendMail(String from, String to, String subject, String text) { this.from = from; this.to = to; this.subject = subject; this.text = text; } public void send() { Properties props = new Properties(); props.put("mail.smtp.host", "192.168.xxx.xxx"); props.put("mail.protocol.port", 25); Session mailSession = Session.getDefaultInstance(props); Message simpleMessage = new MimeMessage(mailSession); InternetAddress fromAddress = null; InternetAddress toAddress = null; try { fromAddress = new InternetAddress(from); toAddress = new InternetAddress(to); } catch (AddressException e) { e.printStackTrace(); } try { simpleMessage.setFrom(fromAddress); simpleMessage.setRecipient(RecipientType.TO, toAddress); simpleMessage.setSubject(subject); simpleMessage.setText(text); Transport.send(simpleMessage); } catch (MessagingException e) { e.printStackTrace(); } } } [/CODE] test client (GUI eka hada ganna) [CODE]import email.sendMail; /** * * @author no_mercy */ public class TestClient { public static void main(String args[]) { String from = "no_mercy@xx.lk"; String to = "no_mercy@xx.lk"; String subject = "Test"; String message = "A test message"; sendMail sendMail = new sendMail(from, to, subject, message); sendMail.send(); System.out.println("Email Sent"); } } [/CODE] me tika run karala balapan. ubata therewi karnna one dey [/QUOTE]
Insert quotes…
Verification
Hata thunen beduwama keeyada? (60 bedeema thuna)
Post reply
Top
Bottom