How to send mail using jsp program
am very new to jsp and doing my final year project. i need to send mails using my jsp program.can anyone say wht to do that is wht to include to send mails using jsp program. n also a sample code to send mail using jsp program.
Thanx in advance
Use below script.
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
<%
Properties props = new Properties();
props.put("mail.smtp.host", "mailserver.com");
Session s = Session.getInstance(props,null);
InternetAddress from = new InternetAddress("[email protected]");
InternetAddress to = new InternetAddress([email protected]");
MimeMessage message = new MimeMessage(s);
message.setFrom(from);
message.addRecipient(Message.RecipientType.TO, to);
message.setSubject("Your subject");
message.setText("Your text");
Transport.send(message);
%>{code}
Similar Messages
-
How can send mails using hotmail/rediffmail domain name?
I have used the below code to send a mail using javamail API?Even when I am sending my application does not have notified any of error/exceptions,But the message is not reached to I have given receipient's address in the to field.
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class Sendmail1 extends HttpServlet {
private String smtpHost;
// Initialize the servlet with the hostname of the SMTP server
// we'll be using the send the messages
public void init(ServletConfig config)
throws ServletException {
super.init(config);
smtpHost = config.getInitParameter("smtpHost");
//smtpHost = "sbm5501";
smtpHost = "www.rediffmail.com";
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException, java.io.IOException {
String from = request.getParameter("from");
String to "[email protected]";
String cc = "[email protected]";
String bcc ="[email protected]";
String smtp ="www.rediffmail.com";
String subject = "hai";
String text = "Hai how r u";
PrintWriter writer = response.getWriter();
if (subject == null)
subject = "Null";
if (text == null)
text = "No message";
String status;
try {
// Create the JavaMail session
java.util.Properties properties = System.getProperties();
if (smtp == null)
smtp = "www.rediffmail.com";
properties.put("mail.smtp.host", smtp);
Session session = Session.getInstance(properties, null);
//to connect
//Transport transport =session.getTransport("smtp");
//transport.connect(smtpHost,user,password);
// Construct the message
MimeMessage message = new MimeMessage(session);
// Set the from address
Address fromAddress = new InternetAddress(from);
message.setFrom(fromAddress);
// Parse and set the recipient addresses
Address[] toAddresses = InternetAddress.parse(to);
message.setRecipients(Message.RecipientType.TO,toAddresses);
Address[] ccAddresses = InternetAddress.parse(cc);
message.setRecipients(Message.RecipientType.CC,ccAddresses);
Address[] bccAddresses = InternetAddress.parse(to);
message.setRecipients(Message.RecipientType.BCC,bccAddresses);
// Set the subject and text
message.setSubject(subject);
message.setText(text);
Transport.send(message);
//status = "<h1>Congratulations,</h1><h2>Your message was sent.</h2>";
} catch (AddressException e)
status = "There was an error parsing the addresses. " + e;
} catch (SendFailedException e)
status = "<h1>Sorry,</h1><h2>There was an error sending the message.</h2>" + e;
} catch (MessagingException e)
status = "There was an unexpected error. " + e;
// Output a status message
response.setContentType("text/html");
writer.println("<title>sendForm</title><body bgcolor= ><b><h3><font color=green><CENTER>CALIBERINFO.COM</CENTER></h3>Your message was sent to recepient(s).<br><font color=red>"+"\n"+to);
writer.println("<br><br><a href=e:/mail/javamail/mail.html>back to compose</a>");
writer.close();
Please any one help me out from this probs.
Awaiting for yours reply,
or give me a reply to: [email protected]
Regards,
@maheshkumar.kHi,
how can send mails using hotmail/rediffmail domain name?In your java application,you specified www.rediffmail.com as your
smtp server.But that is the address of that website.Try will a smtp
server instead.For a list of free smtp servers,please visit http://www.thebestfree.net/free/freesmtp.htm
Hope this helps.
Good Luck.
Gayam.Srinivasa Reddy
Developer Technical Support
Sun Microsystems
http://www.sun.com/developers/support/ -
How to send emails using JSP?
How can i send emails using JSP? what are the things that i will need? please help me asap...thanks
Hi,
This works for me:
<%
String from = "Person"
String to= "my-email-address;
try{
SmtpClient client = new SmtpClient("smtp.stuff.com");
client.from(from);
client.to(to);
PrintStream message = client.startMessage();
message.println("To: " + to);
message.println("Subject: Sending an e-mail");
message.println();
message.println("Groovy :-)");
client.closeServer();
catch (IOException e){
System.out.println("ERROR SENDING EMAIL: "+e);
%> -
How to send mail through java program in solaris server
hi
i am writing java code to send the mail using my company SMTP
,the program is working fine when i run and deploy in windows environment
but at the same time when i deploy the war to sun solaris server ,it is not working
and throwing the Error saying
java.lang.Exception: Invalid Addresses; nested exception is: javax.mail.SendFailedException: 553 sorry, that domain isn't allowed to be relayed thru this MTA without authentication #5.7.1 at jsp.SendMail._jspService(_SendMail.java:137)
i am using the Authentication also using user id and password of same domain and it is able to authenticate
in windows but not in Solaris
where i am making mistake plz
guide.
Saurabhthanks Alan
but i think there is some other problem because same code is
working when i am using in windows as well as i am using authentication method
also but it is not working when running in Solaris Environment
here is the code i am using to send the mail
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "smtp.mycompany.com");//smtp protocol for IIBF
props.put("mail.smtp.starttls.enable","true");//setting start TLS to be true
props.put("mail.smtp.auth", "true");// authentication is false
props.put("mail.smtp.port", port);//setting the port number it can be either 25 or 587
props.put("mail.smtp.username", "noreply");
props.put("mail.smtp.password","noreply");
props.put("mail.debug", "true");
Authenticator auth = new SMTPAuthenticator();
Session session1 = Session.getDefaultInstance(props);
java.util.Properties sessionProperties = new java.util.Properties();
sessionProperties.put("mail.smtp.auth", "true");
message.setFrom(new javax.mail.internet.InternetAddress(From ,"name"));
message.addRecipient(javax.mail.Message.RecipientType.TO, new javax.mail.internet.InternetAddress(To));
message.setText(TextCo);
message.setSubject(subject);
message.setContent(boyd, "text/plain");
message.reply(true);
Transport trans = session1.getTransport("smtp");
trans.connect(SMTP_HOST_NAME, SMTP_AUTH_USER, SMTP_AUTH_PWD);
boolean ddd = trans.isConnected();
message.saveChanges();
trans.sendMessage(message, message.getAllRecipients());
above code is working properly in windows but not in Solaris
plz guide what next to do
thankx in advance
saurabh -
Hi,
I am newbee in Java, I want to send mail to different accounts using java from my website. Plz help me with working example. I am new to java.
Thanks in advance,
devomThanks, but I want to send mail from my WEb page that is in JSP. The arcticle pointed out sends mail in core java. I already know how to send in Core java, but i want to send through JSP. Plz help me.
Thanks in advance,
Devom -
Hi All
I have a requirement in my JSP application to send documents stored on a system by FAX to a fax machine, I had also the requirement to send mails but that was solved using JavaMail. But is there any method through which a FAX can be sent to a FAX machine using JSP.
Please help
SwarajI want to send a message from a system to the client in which he prefer the mode of receiving the message by either E-mail,Phone ,Fax or Mobile.
Plz send me the source .
Swami.N -
Dear friends,
please send me code how to send bulk mails from bsp,
sincerely yoursHi Ganesh,
Look at the following two blogs by Thomas...This will surely help you..!
<a href="/people/thomas.jung3/blog/2004/09/07/sending-e-mail-from-abap--version-46d-and-lower--api-interface E-Mail from ABAP - Version 46D and Lower - API Interface</a>
and
<a href="/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface E-Mail from ABAP - Version 610 and Higher - BCS Interface</a>
This will surely help you.
<b><i>Do reward each useful answer..!</i></b>
Thanks,
Tatvagna. -
How to send fax using java programming
i need to send files in my hard disk through fax using java programming.
i have found on the internet that it is possible to be implemented by using java.comm API and JTAPI. however, i don't know how...does anyone can tell me the details? also, as i know it will be a big project to send fax using such API. is that any other simple way to implement the fax function in java? thx a lot!To cse.mahbub:
Are you aware that you replied to a 5 1/2 year old question?
Please don't do that. Reply only to current questions. -
hi,
i want to send mail from my jsp page.
1) how can i do this
2) do i need any mail server for doin this
thanks
regards
manoji want to send mail from my jsp page.
1) how can i do this
2) do i need any mail server for doin thisRead
http://java.sun.com/developer/onlineTraining/JavaMail/
Rather,
try this:
http://jakarta.apache.org/taglibs/doc/mailer-doc/mailer-1.1/index.html -
Problem in sending mail using Jsp(Jdeveloper9i)
My Code is working when i m sending mail through commandpromt
c:/Jdeveloper/Jdk/bin
But when I m trying it thjrough jsp page than it gives compilation error that not found
Javax.mail.* and Javax.mail.internet.*
I have tried to add mail.jar and activation.jar in c:/Jdeveloper/jdev/jre/lib/ext
If it is wrong place to add these files than plz suggest what i have to do.
Thanks in AdvanceThis is just a relay error. This means that the outbound SMTP server you are using doesn't allow relaying.
Relaying is where the sender is not part of the domain the SMTP server manages. The no-relay concept is pretty common now as spammers often use SMTP servers which allow relaying to send their spam.
The solution is to allow relaying on the SMTP server for your IP address. Another solution which some SMTP servers will implement is to allow relaying for clients who successfully authenticate regardless of their IP address. This is sometimes a better solution because it means you don't have to change anything if your client code moves to a different server.
In your error message:
class javax.mail.SendFailedException: 551 User not local. We don't relay
You can see the SMTP Error Code (551). Look at the SMTP specification (rfc 821 I think) to see what all the error codes mean in case you get another one -
How to send mail using Java Server Pages(JSP)
Plz reply me the code for it
and send me mailmegha_bhagat82: You've posted 3 ill-defined questions in the wrong forum in 4 minutes on the day you registered: I suggest you take a very close look at http://www.catb.org/~esr/faqs/smart-questions.html ... I usually avoid posting that URL to often, as it can be considered rude, but I think in your case it's appropriate.
-
How to send mail using HTML format using tags
Hello experts,
I am currently using FM SO_NEW_DOCUMENT_SEND_API1 to send e-mails to our users' Outlook accounts. Now, I converted its document type from 'RAW' to 'HTM'. I enclosed my texts in HTML tags. But the problem is, I cannot see a thing when I check my message in SCOT. It just opens internet explorer and thats it. Anyway, Below is my code:
get e-mail addresses of controllers in table ZSHIPTO_EMAIL
SELECT * FROM zshipto_email
INTO TABLE it_zshipto_email
WHERE zevent = '2'.
IF sy-dbcnt > 0.
IF NOT it_del_entries[] IS INITIAL.
CLEAR lv_contents.
maildata-obj_name = 'Record Deleted in table ZTS0001'.
maildata-obj_descr = 'Record Deleted in table ZTS0001'.
maildata-obj_langu = sy-langu.
records deleted in ZTS0001 and ZTS_STPGEOLOC
CLEAR: lv_flag, lv_counter.
LOOP AT it_zshipto_email.
CLEAR: it_del_entries, mailtxt.
LOOP AT it_del_entries ASSIGNING <fs_del_entries>.
get name of dealer
SELECT SINGLE name1 FROM kna1
INTO <fs_del_entries>-name1
WHERE kunnr = <fs_del_entries>-kunnr.
IF lv_counter IS INITIAL.
CONCATENATE: '<p>'
'FYI: The ff record/s were deleted in tables'
'ZTS0001 and ZTS_STPGEOLOC by user' sy-uname
'</p>'
INTO lv_contents
SEPARATED BY space.
mailtxt-line = lv_contents.
APPEND mailtxt.
CLEAR: mailtxt, lv_contents.
ENDIF.
APPEND mailtxt.
CONCATENATE: '<p>'
'Dealer :' <fs_del_entries>-kunnr '-'
<fs_del_entries>-name1 '</p>'
INTO lv_contents
SEPARATED BY space.
mailtxt-line = lv_contents.
APPEND mailtxt.
CLEAR: mailtxt, lv_contents.
CONCATENATE: '<p>'
'Ship-To:' <fs_del_entries>-cdseq '</p>'
INTO lv_contents
SEPARATED BY space.
mailtxt-line = lv_contents.
APPEND mailtxt.
CLEAR: mailtxt, lv_contents.
CONCATENATE: '<p>'
'Address:' <fs_del_entries>-zaddress '</p>'
INTO lv_contents
SEPARATED BY space.
mailtxt-line = lv_contents.
APPEND mailtxt.
CLEAR: mailtxt, lv_contents.
CONCATENATE: '<p>'
'Contact person:' <fs_del_entries>-zcperson
'</p>'
INTO lv_contents
SEPARATED BY space.
mailtxt-line = lv_contents.
APPEND mailtxt.
CLEAR: mailtxt, lv_contents.
CONCATENATE: '<p>'
'Contact number:' <fs_del_entries>-zcnumber
'</p>'
INTO lv_contents
SEPARATED BY space.
mailtxt-line = lv_contents.
APPEND mailtxt.
CLEAR: mailtxt, lv_contents.
lv_counter = 1.
ENDLOOP.
APPEND mailtxt.
mailrec-receiver = it_zshipto_email-zemail.
mailrec-rec_type = 'U'.
APPEND mailrec.
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = maildata
document_type = 'HTM'
put_in_outbox = 'X'
commit_work = 'X'
TABLES
object_header = mailtxt
object_content = mailtxt
receivers = mailrec
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CLEAR: mailtxt, mailrec, lv_counter.
REFRESH: mailtxt, mailrec.
ENDLOOP.
ENDIF.
Message was edited by: viraylabHi,
Check this...
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5931ff64-0a01-0010-2bb7-ff2f9a6165a0
Regards
vijay -
Hi All
I am trying to set up James for an organization. I am able to send and recieve mails for only one particular domain(the organization domain) but I am not able to send or recieve mails from any other domain such as yahoo.com or gmail.com. Could anyone help me out.. Please. This is too urgent. Please help me out
thanks
srkpHi,
I think for that u need to take permission from ISP ( Internet service Provider).
Just check it. -
How to send mail using transaction SBWP in HTML format?
Dear All,
When a mail is sent through SBWP transaction in HTML format,
it is finally displayed in text format with html tags, instead of being displayed in html format.
how to retain its HTML format?
Please suggest some solution.
Thanks in advance.Presuming you've already paired the bluetooth, just tap in the text box and you should see a cursor where you can start typing.
Beyond that, what are you seeing or not seeing? how is it acting? -
How to send mail from jsp pageq
Pls help me with this topic
Thanks alotCan you make it clearer. Pls give me a sample code if possible
Thanks alot
Maybe you are looking for
-
Hi, I am using my icloud on my iphone but am unable to find it on my mac book pro. It's not under my system preferences like it shows under the setup. Can I download it again? Or something. I just need to backup some files on my computer and am unabl
-
Best Practice - Battery - Lenovo S440
Hi Forum, I have recently purchased the S440 which is a very well built device. Whilst using it, I have noticed that when the laptop is powered down (not sleep) and the PSU is switched off at the mains, the laptop battery will continue to drain. So t
-
So our computer programming teacher told us to write the conway game of life with a method based off of the notes. Basically, the method written for the game was in the notes, all we had to do write the actual program and display the board. But the o
-
Whenever I send a DNG pic from Lightroom4 to CS6, they only will open directly in CS6, not in Camera Raw. Everything is updated. They use to, until I had a blue screen and had to reinstall everthing.
-
How do I close Mozilla Firefox in order to instal an update of Adobe Flash Player?
I installed FF very recently at the recommendation of Blue Mountain.com as I was unable to send their e-cards with messages. Now I'm trying to update Adobe Flash Player and cannot do so because of the message 'close Moxilla Firefox to continue'. I've