dcsimg
how to define the user name and password .....
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Hyder_ali
Posted On:   Tuesday, December 24, 2002 04:22 AM

when i try to do mail from my site account to another site address i think my send mail bean is not support i received a exception: invalidat address is not permited. my bean is... -------------- import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; public class SendMail { private String To; private String From; private String Subject; private String Contents; private String SmtpHost; private Session session; private String Cc; private MimeBodyPart mbp1; private MimeBodyPart mbp2; private ja   More>>

when i try to do mail from my site account to another site address

i think my send mail bean is not support

i received a exception: invalidat address
is not permited. my bean is...

--------------

import javax.mail.*;

import javax.mail.internet.*;

import javax.activation.*;


public class SendMail

{


private String To;

private String From;

private String Subject;

private String Contents;

private String SmtpHost;

private Session session;

private String Cc;

private MimeBodyPart mbp1;

private MimeBodyPart mbp2;

private java.util.Vector Attachment;

public SendMail(String SmtpHost)

{

this.SmtpHost = SmtpHost;

java.util.Properties prop = System.getProperties();
prop.put("mail.smtp.host", SmtpHost);

session =Session.getInstance(prop, null);

mbp1 = new MimeBodyPart();

Attachment = new java.util.Vector();

}

public void setTo(String To)

{

this.To =To;

}

public void setAttachment(String FileName)

{

Attachment.addElement(FileName);

}

public void setFrom(String From)

{

this.From = From;

}

public void setSubject(String Subject)

{

this.Subject = Subject;

}

public void setContents(String Contents)

{

this.Contents = Contents;

}

public void setSmtpHost(String SmtpHost)

{

this.SmtpHost =SmtpHost;

java.util.Properties prop =System.getProperties();

prop.put("mail.smtp.host", SmtpHost);

session = Session.getInstance(prop, null);

}

public void setCc(String Cc)

{

this.Cc =Cc;

}

public String getTo()

{

return To;

}

public String getFrom()

{

return From;

}

public String getSubject()

{

return Subject;

}

public String getContents(){

return Contents;

}

public String getSmtpHost()

{

return SmtpHost;

}

public String getCc()

{

return Cc;

}



public void Send() throws AddressException,SendFailedException, MessagingException

{

MimeMessage m = new MimeMessage(session);

if(From!=null | To != null)

{

Address from = new InternetAddress(From);

m.setFrom(from); Address [] to =InternetAddress.parse(To);

m.setRecipients(Message.RecipientType.TO,to);

if(Cc != null)

{

Address [] cc = InternetAddress.parse(Cc);
m.setRecipients(Message.RecipientType.CC,cc);

}

m.setSubject(Subject); m.setSentDate(new java.util.Date());

mbp1.setText(Contents);

Multipart mp = new MimeMultipart();

mp.addBodyPart(mbp1);

java.util.Enumeration e = Attachment.elements();

while(e.hasMoreElements())
{

String name = (String)e.nextElement();

mbp2 = new MimeBodyPart();

FileDataSource fds= new FileDataSource(name);

mbp2.setDataHandler(new DataHandler(fds));

mbp2.setFileName(name);

mp.addBodyPart(mbp2);

}

m.setContent(mp);

Transport.send(m);

}

else

{

throw new NullPointerException(" Send Mail Exception : From or To can not be null..");

}

}

}

   <<Less

Re: how to define the user name and password .....

Posted By:   John_Zukowski  
Posted On:   Tuesday, December 24, 2002 04:59 AM

Get it working without the bean first. There are working examples in the FAQ for you.
About | Sitemap | Contact