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
Fetch Mail through a proxy server (Gmail) Java
Send Mail through a proxy server (Gmail) Java
Sending Email From Your Application Using Java Mail
Link

  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,

0 Comments:

Post a Comment

<< Home

 
     
 
  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