Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
427 views
in Technique[技术] by (71.8m points)

java - Is SMTP server required to send mail through web server, by using JavaMail API?

Is a SMTP server required to be able to send mail through a web server, by using JavaMail API? When I am using localhost for sending mail, it works, but when I upload it on server it doesnt work and gives error:

No such smtp provider

How can I solve this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

A SMTP server is always required to be able to send emails, like as a HTTP server is always required to be able to send webpages. This is regardless of the website and the mail API you're using. A HTTP server is not the same as and does usually not include a SMTP server.

You could make use of the SMTP server associated with your own existing email account, such as the one from your ISP or public mailboxes like Gmail, Yahoo, etc. You can find SMTP connection details at their documentation. You usually just need to know the hostname and the port number. The login details are just the same as from your email account.

With the ISP/public mailboxes you're however restricted to using only your own address in the From field of the email and usually also in the amount of emails you're allowed to send at certain intervals. If you'd like to get around this, then you need to install your own SMTP server, for example Apache James, which is Java based, or Microsoft Exchange and so on.

Once you have a SMTP server, then you'll be able to send emails using the JavaMail API or eventually the more convenienced Apache Commons Email.


I forgot to add, if you're using 3rd party web hosting, then it's good to know that most of those 3rd party web hosting providers also offers a SMTP server as well. You'd like to consult the hosting features and figure the connection details in their documentation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...