javax.mail.MessagingException: Unknown SMTP host: MAIL_SMTP_HOST;

Below is the code for the MailerBean program. I am not able to get the correct server or ip address(i'm not sure for the smtp code below:

package business;


/**
* @author wojo
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/



import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.event.*;
import javax.mail.internet.*;

public final class MailerBean extends Object implements Serializable {

/* Bean Properties */
private String to = null;
private String from = null;
private String subject = null;
private String message = null;
public static Properties props = null;
public static Session session = null;

static {
/* Setting Properties for STMP host */
props = System.getProperties();
props.put("mail.smtp.host", "MAIL_SMTP_HOST");
session = Session.getDefaultInstance(props, null);
System.out.println("MailerBean/props.put/AHRC01B1E0151-2");
}
/* Setter Methods */
public void setTo(String to) {
this.to = to;
}

public void setFrom(String from) {
this.from = from;
}

public void setSubject(String subject) {
this.subject = subject;
}

public void setMessage(String message) {
this.message = message;
}
/* Sends Email */
public void sendMail() throws Exception {
if(!this.everythingIsSet())
throw new Exception("Could not send email.");
try {
MimeMessage message = new MimeMessage(session);
message.setRecipient(Message.RecipientType.TO,
new InternetAddress(this.to));
message.setFrom(new InternetAddress(this.from));
message.setSubject(this.subject);
message.setText(this.message);
Transport.send(message);
} catch (MessagingException e) {
throw new Exception(e.getMessage());
}
}

/* Checks whether all properties have been set or not */
private boolean everythingIsSet() {
if((this.to == null) || (this.from == null) ||
(this.subject == null) || (this.message == null))
return false;

if((this.to.indexOf("@) == -1) ||
(this.to.indexOf(".") == -1))
return false;

if((this.from.indexOf("@) == -1) ||
(this.from.indexOf(".") == -1))
return false;

return true;
}
}


Comments

  • [b][red]This message was edited by arb123 at 2004-7-13 2:55:7[/red][/b][hr]
    Try replacing "MAIL_SMTP_HOST" with the DNS name or IP address of the SMTP server you wish to use. You need a SMTP server to route mail to its destination.

    HINT: Have a look at your e-mail client settings to see the information you require.

    ---------------------------------
    [size=1]HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]



  • : [b][red]This message was edited by arb123 at 2004-7-13 2:55:7[/red][/b][hr]
    : Try replacing "MAIL_SMTP_HOST" with the DNS name or IP address of the SMTP server you wish to use. You need a SMTP server to route mail to its destination.
    :
    : HINT: Have a look at your e-mail client settings to see the information you require.
    :
    : ---------------------------------
    : [size=1]HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]
    : thank you
    :
    :
    :



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion