Search results for 'SendMail'. 3 post(s) found.
- 2007/10/16 How to send email in PHP ?
- 2007/08/31 Send An Email Using A Bean
- 2007/08/25 How To Send An E-mail By Code
Send an email from PHP - one line example.
Another posts included in "PHP"
| PHP Switch Example (0) | 2007/10/16 |
| Can PHP switch in strings ? (0) | 2007/10/16 |
| foreach loop (0) | 2007/10/16 |
| How to pass variables via url (0) | 2007/10/16 |
| How to declare array in PHP like C/C++ (0) | 2007/10/16 |
| PHP date and time formatting (0) | 2007/10/16 |
| How to redirect browser in PHP ? (0) | 2007/10/16 |
| How to get current filename as variable ? (0) | 2007/10/16 |
Trackback : Cannot send a trackbact to this post.
-
Subject different money making ideas
2010/01/29 00:29
moneyideas
-
Subject different money making ideas
2010/01/29 09:03
moneyideas
-
Subject different money making ideas
2010/01/31 16:42
moneyideas
This JSP snippets shows how to send an email using a reuasable javabean
<!-- SendMail.jsp -->
<HTML>
<HEAD>
<TITLE>JSP Sample - Send Email</TITLE>
</HEAD>
<BODY background="../../images/Background.gif">
<CENTER>
<BR>
<%--
Prepare the inputs and call the bean method to send the
mail using the API
--%>
<jsp:useBean id="SendMail" class="SendMailBean" scope="page" />
<%
String l_from = request.getParameter("p_from");
String l_to = request.getParameter("p_to");
String l_cc = request.getParameter("p_cc");
String l_bcc = request.getParameter("p_bcc");
String l_subject = request.getParameter("p_subject");
String l_message = request.getParameter("p_message");
String l_SMTPSvr = request.getParameter("p_SMTPServer");
session.setAttribute("SMTPServer",l_SMTPSvr);
String l_result = SendMail.send(l_from,l_to,l_cc,l_bcc,l_subject,l_message,l_SMTPSvr);
%>
<%= l_result %>
<FONT SIZE=3 COLOR="blue">
<A HREF="InputsForm.jsp">Compose Mail</A>
</CENTER>
</BODY>
</HTML>
// SendMailBean.java
import javax.mail.*; //JavaMail packages
import javax.mail.internet.*; //JavaMail Internet packages
import java.util.*; //Java Util packages
public class SendMailBean {
public String send(String p_from,String p_to,String p_cc,String p_bcc,String p_subject,String p_message,String p_SMTPServer) {
String l_result = "<BR><BR><BR><BR><BR><BR><BR>";
// Name of the Host machine where the SMTP server is running
String l_host = p_SMTPServer;
// Gets the System properties
Properties l_props = System.getProperties();
// Puts the SMTP server name to properties object
l_props.put("mail.SMTP.host",l_host);
// Get the default Session using Properties Object
Session l_session = Session.getDefaultInstance(l_props,null);
l_session.setDebug(true); // Enable the debug mode
try {
MimeMessage l_msg = new MimeMessage(l_session); // Create a New message
l_msg.setFrom(new InternetAddress(p_from)); // Set the From address
// Setting the "To recipients" addresses
l_msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(p_to,false));
// Setting the "Cc recipients" addresses
l_msg.setRecipients(Message.RecipientType.CC,InternetAddress.parse(p_cc,false));
// Setting the "BCc recipients" addresses
l_msg.setRecipients(Message.RecipientType.BCC,InternetAddress.parse(p_bcc,false));
l_msg.setSubject(p_subject); // Sets the Subject
// Create and fill the first message part
MimeBodyPart l_mbp = new MimeBodyPart();
l_mbp.setText(p_message);
// Create the Multipart and its parts to it
Multipart l_mp = new MimeMultipart();
l_mp.addBodyPart(l_mbp);
// Add the Multipart to the message
l_msg.setContent(l_mp);
// Set the Date: header
l_msg.setSentDate(new Date());
// Send the message
Transport.send(l_msg);
// If here,then message is successfully sent.
// Display Success message
l_result = l_result + "<FONT SIZE=4 COLOR=\"blue\"><B>Success!</B>"+
"<FONT SIZE=4 COLOR=\"black\"> "+
"<HR><FONT color=green><B>Mail was successfully sent to </B></FONT>: "+p_to+"<BR>";
//if CCed then,add html for displaying info
if (!p_cc.equals(""))
l_result = l_result +"<FONT color=green><B>CCed To </B></FONT>: "+p_cc+"<BR>";
//if BCCed then,add html for displaying info
if (!p_bcc.equals(""))
l_result = l_result +"<FONT color=green><B>BCCed To </B></FONT>: "+p_bcc ;
l_result = l_result+"<BR><HR>";
} catch (MessagingException mex) { // Trap the MessagingException Error
// If here,then error in sending Mail. Display Error message.
l_result = l_result + "<FONT SIZE=4 COLOR=\"blue\"> <B>Error : </B><BR><HR> "+
"<FONT SIZE=3 COLOR=\"black\">"+mex.toString()+"<BR><HR>";
} catch (Exception e) {
// If here,then error in sending Mail. Display Error message.
l_result = l_result + "<FONT SIZE=4 COLOR=\"blue\"> <B>Error : </B><BR><HR> "+
"<FONT SIZE=3 COLOR=\"black\">"+e.toString()+"<BR><HR>";
e.printStackTrace();
}//end catch block
finally {
return l_result;
}
} // end of method send
} //end of bean
<!-- InputForm.jsp -->
HTML>
<HEAD>
<TITLE>JSP Sample - Sending Mail using Java Mail API</TITLE>
</HEAD>
<BODY background="../../images/Background.gif">
<SCRIPT LANGUAGE="JavaScript1.1">
function submission1() {
if(document.forms[0].p_from.value =="" ||
document.forms[0].p_to.value =="" ||
document.forms[0].p_SMTPServer.value =="") {
alert("Host,From and To fields are mandatory.");
return;
}
document.forms[0].action = "SendMail.jsp";
document.forms[0].submit();
}
</SCRIPT>
<CENTER><BR>
<br>
<BR>
<TABLE BGCOLOR=black WIDTH=100% CELLPADDING="1">
<TR><TD>
<CENTER><B><FONT COLOR=Red SIZE=3>Send Mail
</TD></TR>
</TABLE>
<TABLE BORDER=0 >
<TR>
<TD>
<FORM METHOD=POST>
<TABLE BORDER=0 CELLPADDING=4>
<TR>
<TD ALIGN=RIGHT width="124"><b>Mail Server Host</b></TD>
<TD ALIGN=LEFT width="298">
<% String l_svr = (String)session.getAttribute("SMTPServer"); %>
<INPUT TYPE="text" NAME="p_SMTPServer" SIZE=60
VALUE="<%= l_svr!=null ? l_svr : "" %>" >
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT width="124"><b>From</b></TD>
<TD ALIGN=LEFT width="298">
<INPUT TYPE=TEXT SIZE=60 MAXLENGTH=60 NAME="p_from">
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT width="124"><b>To</b></TD>
<TD ALIGN=LEFT width="298">
<INPUT TYPE=TEXT SIZE=60 MAXLENGTH=200 NAME="p_to">
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT width="124"><b>CC</b></TD>
<TD ALIGN=LEFT width="298">
<INPUT TYPE=TEXT SIZE=60 MAXLENGTH=200 NAME="p_cc">
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT width="124"><b>BCC</b></TD>
<TD ALIGN=LEFT width="298">
<INPUT TYPE=TEXT SIZE=60 MAXLENGTH=200 NAME="p_bcc">
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT width="124"><b>Subject</b></TD>
<TD ALIGN=LEFT width="298">
<INPUT TYPE=TEXT SIZE=60 MAXLENGTH=100 NAME="p_subject">
</TD>
</TR>
</TABLE>
<b>Message</b><br>
<TEXTAREA NAME="p_message" ROWS=10 COLS=66 SIZE=2000 WRAP=HARD></TEXTAREA>
<BR><BR>
<CENTER>
<INPUT TYPE=BUTTON VALUE=" Send " onClick="submission1();">
<INPUT TYPE=RESET VALUE="Reset Form"><br>
</CENTER>
</FORM>
</TD>
</TR>
</TABLE>
</CENTER>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>JSP Sample - Send Email</TITLE>
</HEAD>
<BODY background="../../images/Background.gif">
<CENTER>
<BR>
<%--
Prepare the inputs and call the bean method to send the
mail using the API
--%>
<jsp:useBean id="SendMail" class="SendMailBean" scope="page" />
<%
String l_from = request.getParameter("p_from");
String l_to = request.getParameter("p_to");
String l_cc = request.getParameter("p_cc");
String l_bcc = request.getParameter("p_bcc");
String l_subject = request.getParameter("p_subject");
String l_message = request.getParameter("p_message");
String l_SMTPSvr = request.getParameter("p_SMTPServer");
session.setAttribute("SMTPServer",l_SMTPSvr);
String l_result = SendMail.send(l_from,l_to,l_cc,l_bcc,l_subject,l_message,l_SMTPSvr);
%>
<%= l_result %>
<FONT SIZE=3 COLOR="blue">
<A HREF="InputsForm.jsp">Compose Mail</A>
</CENTER>
</BODY>
</HTML>
// SendMailBean.java
import javax.mail.*; //JavaMail packages
import javax.mail.internet.*; //JavaMail Internet packages
import java.util.*; //Java Util packages
public class SendMailBean {
public String send(String p_from,String p_to,String p_cc,String p_bcc,String p_subject,String p_message,String p_SMTPServer) {
String l_result = "<BR><BR><BR><BR><BR><BR><BR>";
// Name of the Host machine where the SMTP server is running
String l_host = p_SMTPServer;
// Gets the System properties
Properties l_props = System.getProperties();
// Puts the SMTP server name to properties object
l_props.put("mail.SMTP.host",l_host);
// Get the default Session using Properties Object
Session l_session = Session.getDefaultInstance(l_props,null);
l_session.setDebug(true); // Enable the debug mode
try {
MimeMessage l_msg = new MimeMessage(l_session); // Create a New message
l_msg.setFrom(new InternetAddress(p_from)); // Set the From address
// Setting the "To recipients" addresses
l_msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(p_to,false));
// Setting the "Cc recipients" addresses
l_msg.setRecipients(Message.RecipientType.CC,InternetAddress.parse(p_cc,false));
// Setting the "BCc recipients" addresses
l_msg.setRecipients(Message.RecipientType.BCC,InternetAddress.parse(p_bcc,false));
l_msg.setSubject(p_subject); // Sets the Subject
// Create and fill the first message part
MimeBodyPart l_mbp = new MimeBodyPart();
l_mbp.setText(p_message);
// Create the Multipart and its parts to it
Multipart l_mp = new MimeMultipart();
l_mp.addBodyPart(l_mbp);
// Add the Multipart to the message
l_msg.setContent(l_mp);
// Set the Date: header
l_msg.setSentDate(new Date());
// Send the message
Transport.send(l_msg);
// If here,then message is successfully sent.
// Display Success message
l_result = l_result + "<FONT SIZE=4 COLOR=\"blue\"><B>Success!</B>"+
"<FONT SIZE=4 COLOR=\"black\"> "+
"<HR><FONT color=green><B>Mail was successfully sent to </B></FONT>: "+p_to+"<BR>";
//if CCed then,add html for displaying info
if (!p_cc.equals(""))
l_result = l_result +"<FONT color=green><B>CCed To </B></FONT>: "+p_cc+"<BR>";
//if BCCed then,add html for displaying info
if (!p_bcc.equals(""))
l_result = l_result +"<FONT color=green><B>BCCed To </B></FONT>: "+p_bcc ;
l_result = l_result+"<BR><HR>";
} catch (MessagingException mex) { // Trap the MessagingException Error
// If here,then error in sending Mail. Display Error message.
l_result = l_result + "<FONT SIZE=4 COLOR=\"blue\"> <B>Error : </B><BR><HR> "+
"<FONT SIZE=3 COLOR=\"black\">"+mex.toString()+"<BR><HR>";
} catch (Exception e) {
// If here,then error in sending Mail. Display Error message.
l_result = l_result + "<FONT SIZE=4 COLOR=\"blue\"> <B>Error : </B><BR><HR> "+
"<FONT SIZE=3 COLOR=\"black\">"+e.toString()+"<BR><HR>";
e.printStackTrace();
}//end catch block
finally {
return l_result;
}
} // end of method send
} //end of bean
<!-- InputForm.jsp -->
HTML>
<HEAD>
<TITLE>JSP Sample - Sending Mail using Java Mail API</TITLE>
</HEAD>
<BODY background="../../images/Background.gif">
<SCRIPT LANGUAGE="JavaScript1.1">
function submission1() {
if(document.forms[0].p_from.value =="" ||
document.forms[0].p_to.value =="" ||
document.forms[0].p_SMTPServer.value =="") {
alert("Host,From and To fields are mandatory.");
return;
}
document.forms[0].action = "SendMail.jsp";
document.forms[0].submit();
}
</SCRIPT>
<CENTER><BR>
<br>
<BR>
<TABLE BGCOLOR=black WIDTH=100% CELLPADDING="1">
<TR><TD>
<CENTER><B><FONT COLOR=Red SIZE=3>Send Mail
</TD></TR>
</TABLE>
<TABLE BORDER=0 >
<TR>
<TD>
<FORM METHOD=POST>
<TABLE BORDER=0 CELLPADDING=4>
<TR>
<TD ALIGN=RIGHT width="124"><b>Mail Server Host</b></TD>
<TD ALIGN=LEFT width="298">
<% String l_svr = (String)session.getAttribute("SMTPServer"); %>
<INPUT TYPE="text" NAME="p_SMTPServer" SIZE=60
VALUE="<%= l_svr!=null ? l_svr : "" %>" >
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT width="124"><b>From</b></TD>
<TD ALIGN=LEFT width="298">
<INPUT TYPE=TEXT SIZE=60 MAXLENGTH=60 NAME="p_from">
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT width="124"><b>To</b></TD>
<TD ALIGN=LEFT width="298">
<INPUT TYPE=TEXT SIZE=60 MAXLENGTH=200 NAME="p_to">
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT width="124"><b>CC</b></TD>
<TD ALIGN=LEFT width="298">
<INPUT TYPE=TEXT SIZE=60 MAXLENGTH=200 NAME="p_cc">
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT width="124"><b>BCC</b></TD>
<TD ALIGN=LEFT width="298">
<INPUT TYPE=TEXT SIZE=60 MAXLENGTH=200 NAME="p_bcc">
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT width="124"><b>Subject</b></TD>
<TD ALIGN=LEFT width="298">
<INPUT TYPE=TEXT SIZE=60 MAXLENGTH=100 NAME="p_subject">
</TD>
</TR>
</TABLE>
<b>Message</b><br>
<TEXTAREA NAME="p_message" ROWS=10 COLS=66 SIZE=2000 WRAP=HARD></TEXTAREA>
<BR><BR>
<CENTER>
<INPUT TYPE=BUTTON VALUE=" Send " onClick="submission1();">
<INPUT TYPE=RESET VALUE="Reset Form"><br>
</CENTER>
</FORM>
</TD>
</TR>
</TABLE>
</CENTER>
</BODY>
</HTML>
Another posts included in "JSP"
| Put Date Time on HTML (0) | 2008/10/27 |
| How to print out text strings on HTML directly ? (0) | 2008/10/27 |
| How to include file in JSP ? (0) | 2008/10/27 |
| JQuery And Function Chaining (0) | 2007/08/31 |
Trackback : Cannot send a trackbact to this post.
-
Subject different money making ideas
2010/01/28 22:47
moneyideas
-
Subject different money making ideas
2010/01/29 06:59
moneyideas
-
Subject different money making ideas
2010/01/31 16:45
moneyideas
Use this function to send an e-mail through your program. You must have the component TNMSMTP from FastNet tools.
This component is included in Delphi 4-5 Professional and Enterprise
procedure TForm1.Button1Click(Sender: TObject);
begin
NMSMTP1.Host := 'mail.host.com';
NMSMTP1.UserID := 'username';
NMSMTP1.Connect;
NMSMTP1.PostMessage.FromAddress := 'webmaster@swissdelphicenter.ch';
NMSMTP1.PostMessage.ToAddress.Text := 'user@host.com';
NMSMTP1.PostMessage.Body.Text := 'This is the message';
NMSMTP1.PostMessage.Subject := 'Mail subject';
NMSMTP1.SendMail;
showmessage('Mail sent !');
end;
begin
NMSMTP1.Host := 'mail.host.com';
NMSMTP1.UserID := 'username';
NMSMTP1.Connect;
NMSMTP1.PostMessage.FromAddress := 'webmaster@swissdelphicenter.ch';
NMSMTP1.PostMessage.ToAddress.Text := 'user@host.com';
NMSMTP1.PostMessage.Body.Text := 'This is the message';
NMSMTP1.PostMessage.Subject := 'Mail subject';
NMSMTP1.SendMail;
showmessage('Mail sent !');
end;
Another posts included in "Delphi"
| How can I hide the caption bar on a form? (0) | 2007/08/25 |
| How To Make A Gradient Filled Form (0) | 2007/08/25 |
| How To Get The Windows Language (0) | 2007/08/25 |
| How To Open Url In Default Webbrowser (0) | 2007/08/25 |
| How To Check If A Soundcard Is Installed (0) | 2007/08/25 |
| How To Change Screen Resolution (0) | 2007/08/25 |
| How To Force The Correct Decimal Separator (0) | 2007/08/25 |
| How To Register Own File Types (0) | 2007/08/25 |
Trackback : Cannot send a trackbact to this post.
-
Subject different money making ideas
2010/01/29 02:13
moneyideas
-
Subject different money making ideas
2010/01/29 10:38
moneyideas
-
Subject different money making ideas
2010/01/31 16:38
moneyideas

Prev

Rss Feed