Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaMail : Subject

Status
Not open for further replies.

jshanoo

Programmer
Apr 2, 2002
287
IN
Hi,
I amreally new to java,
I have program which sends mails continoulsy.This is sentr as attachement.
Now i want to change into inline matter.

so user doesnt have to download and open the attachment.
---------------------------------------------------------
java.util.Date d=new java.util.Date();
String tm=d.getHours()+":"+d.getMinutes();
message.setSubject("# " + strTitle + strSubject + " " + tm);

MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(strMailText);

// create the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
// attach the file to the message
FileDataSource fds=new FileDataSource("c:\\program files\\unijust\\data_out\\"+ strattachfile);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName("Feedback.txt");
// create the Multipart
//and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the Multipart to the message
message.setContent(mp);
message.saveChanges();

Transport transport = session.getTransport("smtp");

transport.addConnectionListener(conHandler);
transport.addTransportListener(transHandler);
transport.connect(mailHost,"","");
transport.sendMessage(message,message.getAllRecipients());
-------------------------------------------------------

Regards
John Philip

*** Even the Best, did the Bad and Made the Best ***

John Philip
 
Why not look at the sun tutorial at ? It will have all you need to know ...

To get you started though :
Code:
	/**
	* Send a message using the contstructor properties.
	* If there is also an attachment to send, add it too.
	*/
	public void send() {
		Properties props = System.getProperties();
		props.put("mail.smtp.host", mxServer);
		Session session = Session.getDefaultInstance(props, null);

		try {
			Message msg = new MimeMessage(session);
			msg.setFrom(new InternetAddress(fromAddress));
			msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toAddress, false));
			msg.setSubject(subject);
			msg.setText(text);
			msg.setHeader("X-Mailer", "JavaMail");

			if (mbp != null) {
				Multipart mp = new MimeMultipart();
				mp.addBodyPart(mbp);
				msg.setContent(mp);
			}

			Transport.send(msg);
		} catch (AddressException ae) {
			ae.printStackTrace();
		} catch (MessagingException me) {
			me.printStackTrace();
		}
	}

(Where mxServer is the exchange server (eg mx1.hotmail.com) - you can find what the mail server is called by doing : "nslookup -type=mx on the command prompt (on certain OS's like W2K and Linux/UNIX)
 
Hi,
Sorry to disturb you again. I am a total Novice in Java.
--------------------------------
mbp1.setText(strMailText);
This creates the inline tezt of mail
------------------------------

// create the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
// attach the file to the message
FileDataSource fds=new FileDataSource("c:\\program files\\unijust\\data_out\\"+ strattachfile);
''' This adds the attachment for the mail
Now i want to append the attachment to the mailtext.
How can i do this

Regards
John Philip

*** Even the Best, did the Bad and Made the Best ***

John Philip
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top