JSP Send mail Instance _jsp programming

Source: Internet
Author: User
Tags mail account
Vishal_donth gave this response on 10/18/2000:
These are are imported from
Java Mail
The Java Mail PAckage either be dowloaded
seperately
Or else is Available in the j2sdkee1.2
(Java Enterprise Edition)

Import javax.mail.*;
Import javax.mail.internet.*;
Import java.util.*;


This function can is used to send the mail
With the parameters given to it
U have to specify the SMTP server through
which u have to send the mail
Since I is trying with a homenetmail
Account I directly sent the mail its server
For sending this mail u need a mail server
which lets u to relay the messages
Try this thing for sending to a
Www.homenetmail.com account because it lets
u send
Mails to the accounts like example try
Sending it to a "abc@homenetmail.com"
Account. Create the mail account in HomeNet
Mail A. If u get no other server which
Supports relaying u can try this
Also.

Use this function in your Servlet to send
Mail by calling the function with the
Parameters

public void SendMail (string toaddr, string subject, String body, String fromaddr) throws remoteexception{
try{
Properties Props = new properties ();
Props.put ("Mail.smtp.host", "mail.homenetmail.com");
Here we specify the SMTP server through
which the mail should be delivered
Session session = Session.getdefaultinstance (props, null);
msg = new MimeMessage (session);
Msg.setfrom (New InternetAddress (FROMADDR));
Specify the "from" address
Internetaddress[] Tos =internetaddress.parse (TOADDR);
Specify the To address
Msg.setrecipients (Message.recipienttype.to,tos);
Msg.setsubject (subject);
Specify the Subject
Msg.settext (body);
Specify the body
Transport.send (msg);
SYSTEM.OUT.PRINTLN ("message is Sent");
}
catch (Exception e) {
System.out.println (e);
}
}

U have to run this function on a computer
Which is directly connected
To the internet but not through a
Proxy......or else use a proxy which
Supports SMTP
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.