Java Send Email

xiaoxiao2021-04-08  435

Mailform.html

<

HTML

>

<

Body

>

<

FORM

Action

= "Sendmail.jsp"

Method

= "POST"

>

<

TABLE

Cellspacing

= "2"

Cellpadding

= "2"

Border

= "1"

>

<

TR

>

<

TD

>

TO:

TD

>

<

TD

>

<

INPUT

Type

= "text"

Name

= "TO"

Size

= "30"

Maxlength

= "30"

>

TD

>

TR

>

<

TR

>

<

TD

>

From:

TD

>

<

TD

>

<

INPUT

Type

= "text"

Name

= "from"

Size

= "30"

Maxlength

= "30"

>

TD

>

TR

>

<

TR

>

<

TD

>

Subject

TD

>

<

TD

>

<

INPUT

Type

= "text"

Name

= "Subject"

Size

= "30"

Maxlength

= "30"

>

TD

>

TR

>

<

TR

>

<

TD

Colspan

= "2"

>

<

Textarea

COLS

= "40"

Rows

= "10"

Name

= "Body"

>

Textarea

>

TD

>

TR

>

<

TR

>

<

TD

>

<

INPUT

Type

= "Submit"

Name

= "Submit"

Value

= "Submit"

>

<

INPUT

Type

= "Reset"

>

TD

>

TR

>

TABLE

>

FORM

>

Body

>

HTML

>

Sendmail.jsp

<

HTML

>

<

HEAD

>

<

Title

>

JSP JavaMail Example

Title

>

HEAD

>

<

Body

>

<%

@ Page Import = "java.util. *"

%>

<%

@ Page Import = "javax.mail. *"

%>

<%

@Page Import = "javax.mail.internet. *"%>

<%

@Page Import = "javax.activation. *"

%>

<%

String host = "yourmailhost"; String to = request.getParameter ( "to"); String from = request.getParameter ( "from"); String subject = request.getParameter ( "subject"); String messageText = request.getParameter ( "body"); boolean sessionDebug = false; Properties Props = System.getProperties (); Props.Put ("mail.host", host); Props.Put ("mail.transport.protocol", "SMTP"); session mailSession = Session.getDefaultInstance (props, null); mailSession.setDebug (sessionDebug); Message msg = new MimeMessage (mailSession); msg.setFrom (new InternetAddress (from)); InternetAddress [] address = {new InternetAddress (to)} Msg.seTrecipients (message.recipienttype.to, address); msg.setSubject (subject); msg.setSentDate (new Date ()); msg.setText (MessageText); Transport.send (MSG); Out.println (" Mail Was Sent to " to); OUT.PRINTLN (" from " from); Out.println (" Using Host " Host ");

%>

TABLE

>

Body

>

HTML

>

转载请注明原文地址:https://www.9cbs.com/read-132918.html

New Post(0)