• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Java Mail

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to create a form to send mail using the JavaMail API. However I keep on getting the message saying that host cannot be found.
I have imported the following:-
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

To start the mail, I have performed the following:-

//Create the JavaMail session
Properties properties = System.getProperties();
properties.put("mail.smtp.host", EmailServer);
Session session = Session.getDefaultInstance(properties, null);
//Construct the message
MimeMessage message = new MimeMessage(session);
//Set the from address
Address fromAddress = new InternetAddress(EmailFrom);
message.setFrom(fromAddress);
//Parse and set the recipient address
Address[] toAddresses = InternetAddress.parse(EmailTo);
message.setRecipients(Message.RecipientType.TO, toAddresses);
Address[] ccAddresses = InternetAddress.parse(EmailCC);
message.setRecipients(Message.RecipientType.CC, ccAddresses);
Address[] bccAddresses = InternetAddress.parse(EmailBCC);
message.setRecipients(Message.RecipientType.BCC, bccAddresses);
//Set the subject and text
message.setSubject(EmailSubject);
message.setText(EmailMessage);
Transport.send(message);
I have used my own ISP email server.

 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java Mail questions are really better asked in the "Other Java APIs" forum, so I've moved this one.
 
Ranch Hand
Posts: 583
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
Well I guess you havent tried to connect to your mail server.
To do that you will have to create a Store object of the following type...
// Get a Store object
Store store = session.getStore("[your Server .. imap or smtp ]");
store.connect(host, user, password);

I guess that should be the problem.
All the best
Regds
Gautham Kasinath
 
Mark Leong
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Gautham.
The problem was actually the server. I cannot specify another smtp server except for the one hosting the servlet. The smtp server does not allow relaying.
 
Evacuate the building! Here, take this tiny ad with you:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic