aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Problem with sending mails Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Problem with sending mails" Watch "Problem with sending mails" New topic
Author

Problem with sending mails

K Kiran Kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 109
Hi,

I am using James 2.1.2 SMTP server, that is installed in my desktop. When I was trying to send mails to external users that are in gmail or yahoo, it is not successful. I didn't get any error after the execution of code below but I didn't get the desired output i.e., I didn't find mails in my gmail or yahoo accounts.

I would like to know the following:
(1) Can we send mails to our personal mail Id(like gmail, etc.) using James?
(2) Please let me know if anything extra I need to configure in the James config.xml file or anywhere else to send mails to any mail ids.
(3) Do I need to install anything else?

Any help will be highly appreciated. This is the code I was using.

public static void main(String[] args)
{
String fromAddress="fromaddress@abc.com";
String smtpHostID="<my system ip address>";
String smtpHostPort="25";
String toAddress="<toaddress>@gmail.com"; //this is my mail address in gmail

Properties props = new Properties();
props.put("mail.smtp.host", smtpHostID);
props.put("mail.smtp.port", smtpHostPort);
try
{
Session session = Session.getDefaultInstance(props,null);
session.setDebug(true);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(fromAddress));

msg.addRecipient(Message.RecipientType.TO, new InternetAddress(toAddress));
msg.setSubject("Hello");
msg.setText("My text -- test");

Transport.send(msg);
}
catch(Exception e)
{
e.printStackTrace();
}
}

Regards,
Kiran.
[ June 11, 2008: Message edited by: K Kiran Kumar ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8895
    
    8

Have you configured James correctly?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
K Kiran Kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 109
Thanks Joe Ess for the URL. I did go through the URL and tried to send mails. Again no error and no output . Not sure what went wrong.

(1) As given in the link, I have tried the first process (steps 1-13). (I have added the servername as abc.com, configured the DNS servers in config.xml). Is DNS server/network obstructing the mails going to destination?

(2) I have tried with and without the DNS servers specification and modified the <authorizedAddresses> tag in the config.xml(as per steps 1-2 at the end of the URL). But still no output.

(3) Is DNS server necessary for this operation? What I was wondering is I keep this setup(install james server ONLY) at homePC and run the code given in my first post with the configuration in point(2)above without DNS server, can I achieve the desired output? I mean sending mails to gmail or yahoo?

I have kept the debug as true and this is what I got in java console:

---------------------------
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG: SMTPTransport trying to connect to host "<my ip address>", port 25
DEBUG SMTP RCVD: 220 my_system_name SMTP Server (JAMES SMTP Server 2.1.2) ready Thu, 12 Jun 2008 15:56:35 +0530 (IST)
DEBUG: SMTPTransport connected to host "<my ip address>", port: 25
DEBUG SMTP SENT: EHLO my_system_name
DEBUG SMTP RCVD: 250 my_system_name Hello my_system_name (<my ip address> ["my ip address>])
DEBUG SMTP: use8bit false
DEBUG SMTP SENT: MAIL FROM:<myuser@abc.com>
DEBUG SMTP RCVD: 250 Sender <myuser@abc.com> OK
DEBUG SMTP SENT: RCPT TO:<myaddress@yahoo.co.in>
DEBUG SMTP RCVD: 250 Recipient <myaddress@yahoo.co.in> OK
Verified Addresses
myaddress@yahoo.co.in
DEBUG SMTP SENT: DATA
DEBUG SMTP RCVD: 354 Ok Send data ending with <CRLF>.<CRLF>
DEBUG SMTP SENT:
.
DEBUG SMTP RCVD: 250 Message received
DEBUG SMTP SENT: QUIT
---------------------------

Also in the james-2.1.2\apps\james\var\mail\outgoing, I found this.
---------------------------
Return-Path: <myuser@abc.com>
Received: from <my_ip_address>([<my_ip_address>])
by my_system_name (JAMES SMTP Server 2.1.2) with SMTP ID 480
for <myaddress@yahoo.co.in>;
Thu, 12 Jun 2008 15:56:35 +0530 (IST)
Message-ID: <11988197.1213266395843.JavaMail.myallias@my_system_name>
From: myuser@abc.com
To: myaddress@yahoo.co.in
Subject: Hello
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Date: Thu, 12 Jun 2008 15:56:35 +0530 (IST)
My text -- bow bow
---------------------------

Once again thanks in advance.

Regards,
Kiran.
[ June 12, 2008: Message edited by: K Kiran Kumar ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8895
    
    8

Does your company or ISP have an SMTP server available? If so, use it rather than James. This will remove one point of failure
K Kiran Kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 109
Hi,
The problem is that I need to implement the setup of James server at client side with some GUI. Our client asked us to use freeware alone to do the task and insisted on increase in the number of dependencies. So I was fighting with James. Earlier I did use our own smtp server using a relay server to send mails and was successful.
Any clue to solve the issue will be highly appreciated.
Regards,
Kiran.
[ June 12, 2008: Message edited by: K Kiran Kumar ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8895
    
    8

Originally posted by K Kiran Kumar:

(3) Is DNS server necessary for this operation? What I was wondering is I keep this setup(install james server ONLY) at homePC and run the code given in my first post with the configuration in point(2)above without DNS server, can I achieve the desired output? I mean sending mails to gmail or yahoo?
[ June 12, 2008: Message edited by: K Kiran Kumar ]


I would think the DNS is necessary because the SMTP gateway has to resolve the destination host for the email with an IP address.
Unfortunately, I've never set up James myself, though I've used JavaMail many times. Your best bet is probably to check the logs in james-2.2.0/apps/james/var/mail/ to see if there's any errors there and check the resources available here for James-specific help.
K Kiran Kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 109
Thanks Joe Ess again for the response.

As per your explanation, I think DNS server will definitely play a role. Do we need to configure anything in the DNS server side? What I feel is there is no problem with my code but I need to do something at the server(DNS/SMTP) end.

Since James is not working for me, I need to search for alternate SMTP servers. I did try with "Ocean Mail Server"(30 day trial version) but got the below error:

javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
javax.mail.SendFailedException: 530 Account is not local, relaying disallowed. <my_mail_address@yahoo.co.in>
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at a.b.c.d.male.main(male.java:62)

Could you please let me know if you have worked with any other free ware SMTP servers (for windows) and if possible could you please provide any docs/urls to download and implement for the same.

Regards,
Kiran.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8895
    
    8



That sounds like you have to tell the server or server account to allow outbound email.
I've never set up an SMTP server, but I do know my employer's set-up restricts outbound emails (email to a different domain) to a list of specific sources.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with sending mails