The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

JSP send mail script not working.

Discussion in 'E-mail Discussions' started by mak_the_admin, Dec 17, 2007.

  1. mak_the_admin

    mak_the_admin Member

    Joined:
    Aug 10, 2007
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    Hello,

    my client have Java source at domain domain.com, but till now
    can't send email

    On local pc the source running well but after upload to server, the
    source can't work

    sample source below please review the source

    If you have sample Java source that running well on your server please
    send to me

    Below is the script.
    ===============================================================

    -------- Source java :
    package package;

    //import java.io.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    //import javax.activation.*;

    import org.apache.commons.mail.DefaultAuthenticator;

    // lib : activasion.jar
    // mail.jar
    // commons.email-1.0.jar

    public class SendApp {
    public static void send(String smtpHost, int smtpPort, String from,
    String to, String subject, String content)
    throws AddressException,
    MessagingException {
    // Create a mail session
    java.util.Properties props = new java.util.Properties();
    props.put("mail.smtp.host", smtpHost);
    props.put("mail.smtp.port", "" + smtpPort);

    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");

    String user = "user";
    String pass = "";
    // password same with cpanel pass

    Authenticator auth = new DefaultAuthenticator(user, pass);
    Session session = Session.getDefaultInstance(props, auth);

    // Construct the message
    Message msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(from));
    msg.setRecipient(Message.RecipientType.TO, new
    InternetAddress(to));
    msg.setSubject(subject);
    msg.setText(content);

    // Send the message
    Transport.send(msg);
    }

    public static void main(String[] args) throws Exception {
    // Send a test message
    send("domain.com", 25, "user@domain.com",
    "user@domain.com", "Subject:
    TestSubject", "TestText");
    System.out.println("finish");
    }
    }
    =================================================================

    Please provide solution if any ASAP.

    Thank you.
     
Loading...

Share This Page