The Artima Developer Community
Sponsored Link

Java Answers Forum
Sending a mail using Java!

4 replies on 1 page. Most recent reply: Oct 18, 2002 8:23 AM by Mark Ferry

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Master

Posts: 7
Nickname: plut
Registered: Mar, 2002

Sending a mail using Java! Posted: Mar 29, 2002 6:23 AM
Reply to this message Reply
Advertisement
I'm working on a project and I'm trying to figure out how to send a mail from my JavaServlet, or an other Java program. My question is : Do any one know how to send a mail using the SMTP protocol? Do I have to use Socket programing?

If you have some source code or know where I can find related information about this please notify me!!


Jay Kandy

Posts: 77
Nickname: jay
Registered: Mar, 2002

Re: Sending a mail using Java! Posted: Mar 29, 2002 7:28 AM
Reply to this message Reply
While you could write to an SMTP port from a servlet, there is an easier way. Use activation.jar and mail.jar from Sun site (JavaMail). And you could do some thing like:

	MimeMessage message = new MimeMessage(session); /* This is not HttpSession */
	message.setFrom( new InternetAddress() );
 
	MimeBodyPart mbp = new MimeBodyPart();
	mbp.setText( "Message body goes here" );
 
	Multipart mp = new MimeMultipart();
	mp.addBodyPart( mbp );			
 
	message.setContent( mp );
 
	message.setSentDate( new Date() );
 
	msg.setSubject( "Subject::" );
	
	InternetAddress[] addresses = { new InternetAddress() };
	message.setRecipients( Message.RecipientType.TO, addresses );							
	Transport.send( message );

Sincerely,
Jay

Yousuf

Posts: 19
Nickname: saeed
Registered: Mar, 2002

Re: Sending a mail using Java! Posted: Apr 1, 2002 3:10 AM
Reply to this message Reply
Well Master..
I did lots of project related to Sending and recieving mail.I have not used any mail Api provided by java.
I made it through simply socket connectivity.if you are new ,you can use Javamail Api privided by sun.Otherwise you have to go through first rfc for SMTP and POP3 and then you can implement all that commands given their in rfc's by simply making socket connectivity.I can help out if you need further help
My Email is "yousuf@security-park.com"
Bye...

yu

Posts: 2
Nickname: learner
Registered: May, 2002

Re: Sending a mail using Java! Posted: May 16, 2002 2:55 AM
Reply to this message Reply
you can use JMail 1.0 , it is make sending and receiving mail so easy.
you can download here
http://toyukin.myetang.com/download

Mark Ferry

Posts: 1
Nickname: mdf
Registered: Oct, 2002

Re: Sending a mail using Java! using CDOSYS Posted: Oct 18, 2002 8:23 AM
Reply to this message Reply
> you can use JMail 1.0 , it is make sending and
> receiving mail so easy.
> you can download here
> http://toyukin.myetang.com/download

There is very little documentation on setting the appropriate configuration for sending emails through port 25 using CDOSYS using java. I figured I'd save someone the time by posting my results:

Make sure to import the following 3rd party classes:

import cdosys.Message;
import cdosys.Configuration;
import com.ms.com.Variant;

Since arguments are expected in Microsoft's Variant type, simply create the variant values you need ():

Variant varSrvPrt = new Variant("http://schemas.microsoft.com/cdo/configuration/smtpserverport");
Variant varPort = new Variant("25");
Variant varSndUsgMethod = new Variant("http://schemas.microsoft.com/cdo/configuration/sendusing");
Variant varSndUsgPrt = new Variant("2");
Variant varSMTPSvr = new Variant("http://schemas.microsoft.com/cdo/configuration/smtpserver");
//Make sure you are using the correct mailserver in the following statement
Variant varHostName= new Variant("mail.domain.com");


Then prepare the email:

// construct the message
Message msg = new Message();
cdosys.Configuration cfg = new cdosys.Configuration();

cfg.getFields().getItem(varSndUsgMethod).setValue(varS ndUsgPrt);
cfg.getFields().getItem(varSrvPrt).setValue(varPort);
cfg.getFields().getItem(varSMTPSvr).setValue(varHostName);
cfg.getFields().Update();

msg.setConfiguration(cfg);
msg.setFrom("nobody@nowhere.com");
msg.setTo("nobody@nowhere.com");
msg.setSub ject("subject");
msg.setTextBody("text");
msg.Send();

Hope it helps!

Mark Ferry

Flat View: This topic has 4 replies on 1 page
Topic: help on applets Previous Topic   Next Topic Topic: Any idea where I can get info on Java beginners guide?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use