[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Using JavaMail in a webapp

Posted on 2013-11-19
4
Medium Priority
?
246 Views
Last Modified: 2013-11-25
Hello,

Im coding a web app in which there is an option to send an email with some data using our Exchange server.

Im using a servlet and a class with the JavaMail api to do that, but I want to authenticate that the person sending the email has a valid Exchange username and password, but I can write anything on those fields and the email is sent without a problem.

This is my mail client code:

public static void sendEmail(String toAddress, String html,String cuenta) 
            throws AddressException,
            MessagingException {
 
        final String userName = "myexchangemail@mailserver.com";
        final String password = "1234";
        Properties properties = new Properties();
        properties.put("mail.transport.protocol", "smtp");
        properties.put("mail.smtp.host", "smtp.mailserver.com");
        properties.put("mail.smtp.auth", "true");
        properties.put("mail.smtp.port", "25");
        
        
        Authenticator auth = new Authenticator() {
            @Override
            public PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(userName, password);
            }
        };
 
        Session session = Session.getInstance(properties, auth);
 
        Message msg = new MimeMessage(session);
 
        msg.setFrom(new InternetAddress(userName));
        InternetAddress[] toAddresses = InternetAddress.parse(toAddress) ;
        msg.setContent(html,"text/html");
        msg.setRecipients(Message.RecipientType.TO, toAddresses);
        msg.setSubject("Test Email");
        msg.setSentDate(new Date());
        Transport.send(msg);
}

Open in new window


I need that only correct username/password combinations of existing exchange mailboxes work on this webapp.
0
Comment
Question by:ScreenFox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 39659975
I need that only correct username/password combinations of existing exchange mailboxes work on this webapp.
But you've hardcoded the credentials - you're not using those of the user ...
0
 

Author Comment

by:ScreenFox
ID: 39661762
Yeah I should have stated that those were for testing purposes only, my point is that I can change those Strings to anything and the server accepts the authentication and sends the email from behalf of the userName (in this case myexchangemail@mailserver.com).

In the final code the userName and password will be entered by the user on the webapp.

What I want is that only actual mailbox users of this Exchange server can login with their userName and password.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 1500 total points
ID: 39662316
What I want is that only actual mailbox users of this Exchange server can login with their userName and password.
That will automatically be the case. If the Exchange server sends mail with arbitrary credentials then it's seriously misconfigured and you should inform the sysadmin for the server
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39673906
:)
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
how to add IIS SMTP to handle application/Scanner relays into office 365.
This video discusses moving either the default database or any database to a new volume.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question