This week's book giveaway is in the Cloud forum.
We're giving away four copies of Terraform in Action and have Scott Winkler on-line!
See this thread for details.
Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

javamail

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody,
I am facing problem while sending a attachment with a mail using JavaMail.I have tried out using MultiPart.I am sending the code for your ready reference.
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.*;
class mail4
{
public static void main(String args[])
{
try
{
java.util.Properties pr = System.getProperties();
Session sess = Session.getInstance(pr,null);

MimeMessage message = new MimeMessage(sess);
message.addHeader("X-Priority","1");
message.setFrom(new InternetAddress("ssengupta@dvlp.com"));

message.addRecipient(Message.RecipientType.TO,new InternetAddress("ssengupta@dvlp.com"));
message.setSubject(" javamail");

MimeBodyPart mb1 = new MimeBodyPart();
mb1.setHeader("Content-Transfer Encoding", "UUENCODE"); // tried using "Base64"
mb1.setText(" hello how are you...");

MimeBodyPart mb2 = new MimeBodyPart();
// mb2.setDisposition(mb2.ATTACHMENT);
mb2 = new MimeBodyPart();
mb2.setHeader("Content-Transfer Encoding", "UUENCODE");
FileDataSource fds = new FileDataSource("c:\\jsdk2.1\\settings.txt");
mb2.setDataHandler(new DataHandler(fds));

// mb2.setFileName(fds.getName());


MimeMultipart p = new MimeMultipart();
p.addBodyPart(mb1);
p.addBodyPart(mb2);
message.setContent(p);


Transport trans = sess.getTransport("smtp");
trans.connect("191.1.56.2"," "," ");

trans.sendMessage(message,message.getAllRecipients());
trans.close();
} catch(Exception e)
{
System.out.println(e);
}

}
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic