email from java

I am trying to understand how it all works:

I found some code here: http://www.rgagnon.com/javadetails/java-0504.html

Code:

import javax.mail.*;

import javax.mail.internet.*;

import java.util.Properties;

class SimpleMail{

publicstaticvoid main(String[] args)throws Exception{

System.out.println("Sending mail...");

Properties props =new Properties();

props.setProperty("mail.transport.protocol","smtp");

props.setProperty("mail.host","smtp.mymailserver.com");

props.setProperty("mail.user","myuser");

props.setProperty("mail.password","mypwd");

Session mailSession = Session.getDefaultInstance(props,null);

mailSession.setDebug(true);

Transport transport = mailSession.getTransport();

MimeMessage message =new MimeMessage(mailSession);

message.setSubject("HTML mail with images");

message.setFrom(new InternetAddress("me@sender.com"));

message.setContent("<h1>Hello world</h1>","text/html");

message.addRecipient(Message.RecipientType.TO,

new InternetAddress("you@receiver.com"));

transport.connect();

transport.sendMessage(message,

message.getRecipients(Message.RecipientType.TO));

transport.close();

}

}

What is this:

props.setProperty("mail.transport.protocol","smtp");

props.setProperty("mail.host","smtp.mymailserver.com");

props.setProperty("mail.user","myuser");

props.setProperty("mail.password","mypwd");

what are those parameters that are being set? (for ex. mail.transport.protocol and so on)?

Do I need to configure smtp somehow? What is all that?

[2821 byte] By [ThisObjecta] at [2007-10-2 3:28:59]
# 1
http://www.google.com/search?hl=en&q=javamail+tutorial
RichardTheLionHearteda at 2007-7-15 22:38:45 > top of Java-index,Java Essentials,Java Programming...
# 2
Well, thanks.I need to send a confirmation email to the user. That email should contain a link which can access my back end java program. How can this be done?Thanks
ThisObjecta at 2007-7-15 22:38:45 > top of Java-index,Java Essentials,Java Programming...
# 3
?
ThisObjecta at 2007-7-15 22:38:45 > top of Java-index,Java Essentials,Java Programming...
# 4
Well, for that you should probably send a html email and set those properties to the correct values (i.e. host and user/pass of your smtp server).
-Kayaman-a at 2007-7-15 22:38:45 > top of Java-index,Java Essentials,Java Programming...
# 5

To send an email, your app should use Simple Mail Transfer Protocol (SMTP) to create a connection to SMTP server of your ISP. So you need to get known about SMTP server host and whether is requires authentication.

Then in the sample you need to substitute

1) "smtp.mymailserver.com" with your SMTP server name

2) "myuser" and "mypwd" with username and password told you by your ISP

vsukhareva at 2007-7-15 22:38:45 > top of Java-index,Java Essentials,Java Programming...
# 6

hi,

is there any free online SMTP server avaible in the net ?

i dont have SMTP server. i can download it . but i dont know my ISP's configauration . is there any free online SMTP server available in the net for testing java mail so that i could use there host name,user,password etc for testing java mail program.

does yahoo/google provides any SMTP server

variablea at 2007-7-15 22:38:45 > top of Java-index,Java Essentials,Java Programming...
# 7

>> is there any free online SMTP server avaible in the net ?

If there were, it would be easy to send a million spam e-mails, wouldn't it? Note that there are probably some around (but you can search for those yourself).

You could also use James, a Java-based open source mail server; see http://james.apache.org/.

levi_ha at 2007-7-15 22:38:45 > top of Java-index,Java Essentials,Java Programming...
# 8

Nice,

I found out the name of smtp and pop servers form my ISP.

However, what are the benefits/downs of using it from my ISP.

Is it better to use James and set it up myself?

And I still have the same question :)

I need to send an email which contains a link. A user can click that link.

Action: once user clicks the link some records on the back end in mysql are updated.

How can this be done?

thanks

ThisObjecta at 2007-7-15 22:38:45 > top of Java-index,Java Essentials,Java Programming...
# 9

> I found out the name of smtp and pop servers form my

> ISP.

> However, what are the benefits/downs of using it from

> my ISP.

> Is it better to use James and set it up myself?

I used James for some time but I had a problem where several major providers (AOL were the major problem) would not accept emails from James. If one searches the AOL web site there is (somewhere) a page that details the AOL policy. I can't remember the detail but it is something about smtp servers need to register with AOL.

sabre150a at 2007-7-15 22:38:45 > top of Java-index,Java Essentials,Java Programming...
# 10
I am not using AOL though
ThisObjecta at 2007-7-15 22:38:45 > top of Java-index,Java Essentials,Java Programming...
# 11

> I am not using AOL though

But are you sending emails to an AOL address? That is what matters.

There are other problem sites so it is worth checking, The default setup of Apache James SMTP server does not inform you of a non-delivery problem for many hours. I had to change the setup to tell me after at most 5 minutes.

sabre150a at 2007-7-15 22:38:45 > top of Java-index,Java Essentials,Java Programming...
# 12

I do not think I'll go with James.

Oce again:

I need to send an email which contains a link. A user can click that link.

Action: once user clicks the link some records on the back end in mysql are updated.

So, which URL do I send to the user?

How can this be done?

ThisObjecta at 2007-7-15 22:38:45 > top of Java-index,Java Essentials,Java Programming...
# 13
>> I need to send an email which contains a link. A user can click that link.>> Action: once user clicks the link some records on the back end in mysql are>> updated.You could write a servlet.
levi_ha at 2007-7-15 22:38:45 > top of Java-index,Java Essentials,Java Programming...
# 14
but what the URL is going to look like?
ThisObjecta at 2007-7-15 22:38:45 > top of Java-index,Java Essentials,Java Programming...
# 15
That's the best part - you can decide!But serious, I don't know how experienced you are wrt programming servlets, but this should be relatively easy.
levi_ha at 2007-7-20 17:50:40 > top of Java-index,Java Essentials,Java Programming...
# 16
any ideas?
ThisObjecta at 2007-7-20 17:50:40 > top of Java-index,Java Essentials,Java Programming...
# 17
> but what the URL is going to look like?It will look an awful lot like a URI but with a tad bit more information.Good luck.
filestreama at 2007-7-20 17:50:40 > top of Java-index,Java Essentials,Java Programming...
# 18
Here is the detailed procedure.When a user receives an email which contains a link he/she can click on it.Action: when the user clicks on that link a certain cell in mysql tableis set to true. Before user clicks on it the cell's value is false.?
ThisObjecta at 2007-7-20 17:50:40 > top of Java-index,Java Essentials,Java Programming...