Amoraboti - Program
Rashed - Uz - Zaman (Rasel)
  Home About Me Brainstorming Facebook Fan Page Contact    
  Author
I'm Rz Rasel
From Bangladesh

  Archives
April 2010
May 2010
January 2011
February 2011
January 2012
February 2012
March 2012

  Current

  Previous Posts
d
e
2
B
Php:- Check For Valid Email Address
How To Insert Unicode Values To MySQL Using Java
Multiple Checkbox Select/Deselect JavaScript And j...
Dynamically Add/Remove rows in HTML table using Ja...
Dynamically add button, textbox, input, radio elem...
Changing Form Input (Textbox) Style on Focus using...

  My Link
Islam And We
My Diary (Bangla)
My Diary (English)
My Lyrics (Bangla)
My Lyrics (English)
My Poem (Bangla)
My Poem (English)
My Story (Bangla)
My Story (English)
General Knowledge
Fun And Jokes
Lyrics (Bangla)
Lyrics (English)
Lyrics (Hindi)
Quotations
 
 
  Without SSL connection, Normal SMTP Java  
  Saturday, April 3, 2010  
 

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.UnsupportedEncodingException;
import java.security.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeUtility;
public class AttachExample {
public static void main (String args[]) throws Exception
{
System.getProperties().put("proxySet","true");
System.getProperties().put("socksProxyPort","1080");
System.getProperties().put("socksProxyHost","192.168.155.1");
Properties props = System.getProperties();

String from = "xxxxx@spymac.com";
String to = "xxxx@yahoo.com";
String filename = "AttachExample.java";


// Get system properties
final String username = "USERNAME";
final String password = "PASSWORD";

props.put("mail.user", username);
props.put("mail.host", "mail.spymac.com");
props.put("mail.debug", "true");
props.put("mail.store.protocol", "pop3");
props.put("mail.transport.protocol", "smtp");


Session session = Session.getDefaultInstance(props,
new Authenticator(){
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}});

// Define message
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Hello JavaMail Attachment");
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText("Here's the file");
// Create a Multipart
Multipart multipart = new MimeMultipart();
// Add part one
multipart.addBodyPart(messageBodyPart);
// // Part two is attachment // // Create second body part
messageBodyPart = new MimeBodyPart();
// Get the attachment
DataSource source = new FileDataSource(filename);
// Set the data handler to the attachment
messageBodyPart.setDataHandler(new DataHandler(source));
// Set the filename
messageBodyPart.setFileName(filename);
// Add part two
multipart.addBodyPart(messageBodyPart);
// Put parts in message
message.setContent(multipart);
// Send the message
Transport.send(message);
}
}

Labels:

 
  posted by Rz Rasel At 12:35 PM, ,  
     
  Fetch Mail through a proxy server (Gmail) Java  
   
 

import java.io.UnsupportedEncodingException;
import java.security.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeUtility;

public class GmailFetch {

public static void main(String argv[]) throws Exception {

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";

// Get a Properties object
Properties props = System.getProperties();
props.setProperty("proxySet","true");
props.setProperty("socksProxyHost","192.168.155.1");
props.setProperty("socksProxyPort","1080");

props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.pop3.socketFactory.fallback", "false");
props.setProperty("mail.pop3.port", "995");
props.setProperty("mail.pop3.socketFactory.port", "995");

Session session = Session.getDefaultInstance(props,null);


URLName urln = new URLName("pop3","pop.gmail.com",995,null,
"USERNAME", "PASSWORD");
Store store = session.getStore(urln);
Folder inbox = null;
try {
store.connect();
inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
FetchProfile profile = new FetchProfile();
profile.add(FetchProfile.Item.ENVELOPE);
Message[] messages = inbox.getMessages();
inbox.fetch(messages, profile);
System.out.println("Inbox Number of Message" + messages.length);
for (int i = 0; i < style="color:navy;">{

String from = decodeText(messages[i].getFrom()[0].toString());
InternetAddress ia = new InternetAddress(from);System.out.println("FROM:" + ia.getPersonal()+'('+ia.getAddress()+')');

System.out.println("TITLE:" + messages[i].getSubject());

System.out.println("DATE:" + messages[i].getSentDate());
}
}
finally {
try {
inbox.close(false);
}
catch (Exception e) {
}
try {
store.close();
}
catch (Exception e) {
}
}
}

protected static String decodeText(String text)
throws UnsupportedEncodingException {
if (text == null)
return null;
if (text.startsWith("=?GB") || text.startsWith("=?gb"))
text = MimeUtility.decodeText(text);
else
text = new String(text.getBytes("ISO8859_1"));
return text;
}
}

Labels:

 
  posted by Rz Rasel At 12:33 PM, ,  
     
  Send Mail through a proxy server (Gmail) Java  
   
 

import java.security.Security;
import java.util.Date;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class GmailSender {

public static void main(String[] args) throws AddressException, MessagingException {


Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
// Get a Properties object
Properties props = System.getProperties();
props.setProperty("proxySet","true");
props.setProperty("socksProxyHost","192.168.155.1");
props.setProperty("socksProxyPort","1080");
props.setProperty("mail.smtp.host", "smtp.gmail.com");
props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.port", "465");
props.setProperty("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.store.protocol", "pop3");
props.put("mail.transport.protocol", "smtp");
final String username = "USERNAME";
final String password = "PASSWORD";
Session session = Session.getDefaultInstance(props,
new Authenticator(){
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}});

// -- Create a new message --
Message msg = new MimeMessage(session);

// -- Set the FROM and TO fields --
msg.setFrom(new InternetAddress("xxxxxx@gmail.com"));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("xxxxxx@yahoo.com",false));
msg.setSubject("Hello");
msg.setText("How are you");
msg.setSentDate(new Date());
Transport.send(msg);
System.out.println("Message sent.");
}
}

Labels:

 
  posted by Rz Rasel At 12:26 PM, ,  
     
  Sending Email From Your Application Using Java Mail  
   
 
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException
{
boolean debug = false;

//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.jcom.net");

// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);

// create a message
Message msg = new MimeMessage(session);

// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);

InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++) { addressTo[i] = new InternetAddress(recipients[i]); } msg.setRecipients(Message.RecipientType.TO, addressTo);

// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader("MyHeaderName", "myHeaderValue");

// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
}

To Send a Email, from your Program, just call the above method, With the following parameters,

String to -- Email Address of the Recipient

String subject -- Email Subject

String message -- Content or Body of the Message

String from -- Your (Senders) Email Address

smtp.jcom.net -- Replace this with your ISP's SMTP address.

That's it, you are all set to send a Email.

If your SMTP Server need you to do Authentication using Username and Password before Sending out mail, download the complete code from here SendMailUsingAuthentication.java

Labels:

 
  posted by Rz Rasel At 12:24 PM, ,  
     
 
  Problem In Font
Download then zip file unzip and install in your system. Or normal font file just install in your system font folder. Rz Rasel
Bangla Font
Bangla Font

  Find Me In Facebook
 
 

   aaaa
 

   aaaa
 
 
Copyright © 2010 - Amoraboti - Program. ® All right reaserved. Design and developed by:- Rz Rasl