Hi,
I am doing send some values(signup form::firstname,lastname,title,organization)
to mail id using javamail at the same time it should store in database, my problem is how to fetch values from database and store it in array.
I need urgently ,Please help me.
thanks in advance.
20 23754
Hi,
I am doing send some values(signup form::firstname,lastname,title,organization)
to mail id using javamail at the same time it should store in database, my problem is how to fetch values from database and store it in array.
I need urgently ,Please help me.
thanks in advance.
You can connect to a database using JDBC. Do you know anything about it?
You can connect to a database using JDBC. Do you know anything about it?
Post the Code so far you did.
Then experts are here to solve your problem.
And remember, while you posting the code then don't forget to use Code Tag.
Please read the guidelines before Posting.
OK.
Best of luck with your try.
Kind regards,
Dmjpro.
Hi,
I post the code here, -
import javax.servlet.*;
-
import javax.servlet.http.*;
-
import java.io.*;
-
import java.sql.*;
-
import javax.mail.*;
-
import javax.mail.internet.*;
-
import javax.mail.event.*;
-
import java.net.*;
-
import java.util.*;
-
-
-
public class mail3 extends HttpServlet
-
-
{
-
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
-
{
-
-
PrintWriter out=response.getWriter();
-
response.setContentType("text/html");
-
try
-
{
-
Properties props=new Properties();
-
props.put("mail.smtp.host","mail.cygnussoftwares.com");
-
Session session = Session.getDefaultInstance(props,null);
-
String fname = request.getParameter("firstname");
-
String lname = request.getParameter("lastname");
-
String tit = request.getParameter("Title");
-
String org = request.getParameter("organization");
-
String add1 = request.getParameter("Address1");
-
String add2 = request.getParameter("address2");
-
String city = request.getParameter("city");
-
String state = request.getParameter("state");
-
String country = request.getParameter("country");
-
String organizationSize= request.getParameter("turnover");
-
String phone= request.getParameter("phone");
-
String email= request.getParameter("emailid");
-
String product= request.getParameter("product");
-
-
//String recipients= "devteam@yahoo.com"
-
-
//={"devteam@yahoo.com","sathya@gmail.com","pnithya@yahoo.co.in"};
-
-
-
String k=fname+lname+tit+org+add1+add2+city+state+country+organizationSize+product+phone+email;
-
String subject="Product Inquiry Form";
-
-
String FirstName="FirstName:";
-
String LastName="LastName:";
-
String Title="Title:";
-
String Organization="Organization:";
-
String Address1="Address1:";
-
String Address2="Address2:";
-
String City="City:";
-
String State="State:";
-
String Country="Country:";
-
String OrganizationSize="OrganizationSize:";
-
String Phone="Phone:";
-
String Email="E-Mail:";
-
String Product="Product";
-
-
//String recipients;
-
-
try
-
{
-
//Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
-
//Connection cn = DriverManager.getConnection("jdbc:microsoft:sqlserver://CSISERVER2:1433;DatabaseName=web Hosting","sa","sa") ;
-
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
-
Connection cn = DriverManager.getConnection("jdbc:odbc:send", " ", " ");
-
Statement st = cn.createStatement();
-
ResultSet rs = st.executeQuery("select * from send ");
-
-
//st.executeUpdate("insert into sendmail values('"+fname+"','"+lname+"','"+tit+"','"+org+"',
-
'"+add1+"','"+add2+"','"+city+"','"+state+"',
-
'"+country+"','"+organizationSize+"','"+product+"','"+phone+"','"+email+"')");
-
//out.println("Record inserted successfully ........");
-
-
-
String to="";
-
-
while(rs.next())
-
{
-
to = rs.getString(1);
-
-
}
-
System.out.println("the name is :"+to);
-
-
}
-
catch(Exception e)
-
{
-
e.printStackTrace();
-
}
-
-
MimeMessage message = new MimeMessage(session);
-
message.setRecipient(Message.RecipientType.TO,new InternetAddress(to));
-
-
/*InternetAddress[] addressTo = new InternetAddress[recipients.length];
-
for (int i = 0; i < recipients.length; i++)
-
{
-
addressTo[i] = new InternetAddress(recipients[i]);
-
}
-
message.setRecipients(Message.RecipientType.TO, addressTo);*/
-
-
-
//message.setFrom(new InternetAddress(from));
-
-
if(subject!=null)
-
{
-
message.setSubject(subject);
-
}
-
else
-
{
-
message.setSubject("");
-
}
-
-
-
if (k!=null)
-
{
-
message.setContent("<html><body ><table border=1><tr><td>"+FirstName+"</td><td>"+fname+"</td></tr>
-
<tr><td>"+LastName+"</td><td>"+lname+"</td></tr><tr><td>"+Title+"</td><td>
-
"+tit+"</td></tr><tr><td>"+Organization+"</td>
-
<td>"+org+"</td></tr><tr><td>"+Address1+"</td>
-
<td>"+add1+"</td></tr><tr><td>"+Address2+"</td>
-
<td>"+add2+
-
"</td></tr><tr><td>"+City+"</td>
-
<td>"+city+"</td></tr><tr><td>"+State+"</td>
-
<td>"+state+"</td></tr><tr><td>"+Country+"</td>
-
<td>"+country+"</td></tr><tr><td>"+OrganizationSize+"</td>
-
<td>"+organizationSize+ "</td></tr><tr><td>"+Product+"</td><td>"+product+"</td></tr>
-
<tr><td>"+Phone+"</td><td>"+phone+"</td></tr><tr>
-
<td>"+Email+"</td><td>"+email+"</td></tr></table>
-
</body></html>","text/HTML");
-
}
-
else
-
{
-
message.setContent("","text/HTML");
-
}
-
-
-
Transport.send(message);
-
//out.println("The Mail has been sent");
-
response.sendRedirect("../signUp/success.html");
-
}
-
catch (Exception e)
-
{
-
out.println("ERROR....."+e);
-
System.out.println("ERROR....."+e);
-
}
-
-
}
-
}
-
-
Which values do you want to store in an array?
You do know how to declare arrays, right?
Hi,
Get multiple mail ids from database and store that in array, and then send that as to like new InternetAddress(to),
first I got send to multiple mail ids without database using array like -
String recipients=={"devteam@yahoo.com","sathya@gmail.com","pnithya@yahoo.co.in"};
-
-
InternetAddress[] addressTo = new InternetAddress[recipients.length];
-
for (int i = 0; i < recipients.length; i++)
-
{
-
addressTo[i] = new InternetAddress(recipients[i]);
-
}
-
message.setRecipients(Message.RecipientType.TO, addressTo);
-
now I want, how to store the resultSet values in array
Hi,
Get multiple mail ids from database and store that in array, and then send that as to like new InternetAddress(to),
first I got send to multiple mail ids without database using array like -
String recipients=={"devteam@yahoo.com","sathya@gmail.com","pnithya@yahoo.co.in"};
-
-
InternetAddress[] addressTo = new InternetAddress[recipients.length];
-
for (int i = 0; i < recipients.length; i++)
-
{
-
addressTo[i] = new InternetAddress(recipients[i]);
-
}
-
message.setRecipients(Message.RecipientType.TO, addressTo);
-
now I want, how to store the resultSet values in array
Use an Arraylist instead since you may not know how many times rs.next is going to be called. Then you just do - list.add(rs.getString(1));
Hi,
Thanks for your solution, if i put this code like list.add(rs.getstring(1)) other simple coding means i got all the values from database, but in javamail
I got one error like
cannot resolve symbol,
symbol:variable list -
ArrayList list = new ArrayList();
-
-
-
while(rs.next())
-
{
-
list.add(rs.getString(1));
-
}
-
-
MimeMessage message = new MimeMessage(session);
-
message.setRecipient(Message.RecipientType.TO,new InternetAddress(list));
-
-
Hi,
Thanks for your solution, if i put this code like list.add(rs.getstring(1)) other simple coding means i got all the values from database, but in javamail
I got one error like
cannot resolve symbol,
symbol:variable list -
ArrayList list = new ArrayList();
-
-
-
while(rs.next())
-
{
-
list.add(rs.getString(1));
-
}
-
-
MimeMessage message = new MimeMessage(session);
-
message.setRecipient(Message.RecipientType.TO,new InternetAddress(list));
-
-
It's your try/catch blocks that are putting list out of scope as soon as you exit the try/catch block. Either declare the ArrayList before the try/catch block or move your catch blocks to the end of the code.
Hi,
I put the code like -
while(rs.next())
-
{
-
list.add(rs.getString(1));
-
}
-
}
-
catch(Exception e)
-
{
-
out.println(e);
-
}
-
-
-
MimeMessage message = new MimeMessage(session);
-
message.setRecipient(Message.RecipientType.TO,new InternetAddress(list));
-
means I got the following error,
cannot resolve symbol
symbol:constractor InternetAddress (java.util.ArrayList)
If I put the code like -
while(rs.next())
-
{
-
list.add(rs.getString(1));
-
}
-
}
-
catch(Exception e)
-
{
-
out.println(e);
-
}
-
-
-
MimeMessage message = new MimeMessage(session);
-
message.setRecipient(Message.RecipientType.TO,new InternetAddress("list"));
-
this means I didnot get compile time error,
but I got run time error like
ERROR.....javax.mail.SendFailedException: Invalid Addresses; nested exception is: class com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Hello [125.22.243.43], Policy rejection on the target address:
Please help me
Thanks in advance
Read the docs for ArrayList class to see how to use the get method to get values out of an arraylist.
Also, you'll have to make sure you're passing the correct address format because the InternetAddress constructor does strict parsing on it.
Hi,
I tried many ways, but I didnot get the answer,Please help me.
I think it is typecast error, after fetching the values from database I print that values using out.println(list) , I got the output [dev@yahoo.com].
and then I tried to convert from arraylist to string, I had no compile time error,
but I got runtime error, that time also I print that values using out.println(list).
If I pass the values like this - ]
-
Strint to={"dev@yahoo.com","a@yahoo.com"}
-
message.setRecipient(Message.RecipientType.TO,new InternetAddress(to));
-
means I got the correct answer.
but I didnot have any solution how to convert [a@yahoo.com] to "a@yahoo.com", Please the solution.
Hi,
I tried many ways, but I didnot get the answer,Please help me.
I think it is typecast error, after fetching the values from database I print that values using out.println(list) , I got the output [dev@yahoo.com].
and then I tried to convert from arraylist to string, I had no compile time error,
but I got runtime error, that time also I print that values using out.println(list).
If I pass the values like this - ]
-
Strint to={"dev@yahoo.com","a@yahoo.com"}
-
message.setRecipient(Message.RecipientType.TO,new InternetAddress(to));
-
means I got the correct answer.
but I didnot have any solution how to convert [a@yahoo.com] to "a@yahoo.com", Please the solution.
Hi,
It is very simple..... Use get method of list as -
-
list.get(i);//where i is the position of element in the list
-
If list contain class object or String then typeCast it.. -
-
(object)list.get(i); // ..or
-
(String)list.get(i);
-
Hi,
I tried that way even then I didnot get the answer, I put the code like this -
-
ArrayList list = new ArrayList();
-
while(rs.next())
-
{
-
String to=rs.getString(1);
-
list.add(to);
-
}
-
String m="";
-
for(int i=0;i<list.size();i++)
-
{
-
m += list.get(i).toString();
-
}
-
String to=m;
-
out.println(to);
-
}
-
catch(Exception e)
-
{
-
out.println(e);
-
}
-
-
-
MimeMessage message = new MimeMessage(session);
-
message.setRecipient(Message.RecipientType.TO,new InternetAddress("to"));
-
I got the following error,
"sruthi@yahoo.com" ERROR.....javax.mail.SendFailedException: Invalid Addresses; nested exception is: class com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Hello [125.22.243.43], Policy rejection on the target address:
Hi,
I tried that way even then I didnot get the answer, I put the code like this -
-
ArrayList list = new ArrayList();
-
while(rs.next())
-
{
-
String to=rs.getString(1);
-
list.add(to);
-
}
-
String m="";
-
for(int i=0;i<list.size();i++)
-
{
-
m += list.get(i).toString();
-
}
-
String to=m;
-
out.println(to);
-
}
-
catch(Exception e)
-
{
-
out.println(e);
-
}
-
-
-
MimeMessage message = new MimeMessage(session);
-
message.setRecipient(Message.RecipientType.TO,new InternetAddress("to"));
-
I got the following error,
"sruthi@yahoo.com" ERROR.....javax.mail.SendFailedException: Invalid Addresses; nested exception is: class com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Hello [125.22.243.43], Policy rejection on the target address:
Remove the quotes in - message.setRecipient(Message.RecipientType.TO,new InternetAddress("to"));
So you have - message.setRecipient(Message.RecipientType.TO,new InternetAddress(to));
Hi,
If I remove the quotes , I got the compile time error,
cannot resolve symbol
symbol:variable m
location:message.setRecipient(Message.RecipientTyp e.TO,new InternetAddress(m)); -
ArrayList list = new ArrayList();
-
while(rs.next())
-
{
-
String to=rs.getString(1);
-
list.add(to);
-
}
-
String m="";
-
for(int i=0;i<list.size();i++)
-
{
-
m += list.get(i).toString();
-
}
-
MimeMessage message = new MimeMessage(session);
-
message.setRecipient(Message.RecipientType.TO,new InternetAddress(m));
-
Please help me,
cannot resolve symbol
symbol:variable m
location:message.setRecipient(Message.RecipientTyp e.TO,new InternetAddress(m));
... -
message.setRecipient(Message.RecipientType.TO,new InternetAddress(m));
-
Why is it new InternetAddress(m) instead of new InternetAddress(to)? It doesn't recognize m! It used to be " to", didn't it?
Hi,
If I remove the quotes , I got the compile time error,
cannot resolve symbol
symbol:variable m
location:message.setRecipient(Message.RecipientTyp e.TO,new InternetAddress(m)); -
ArrayList list = new ArrayList();
-
while(rs.next())
-
{
-
String to=rs.getString(1);
-
list.add(to);
-
}
-
String m="";
-
for(int i=0;i<list.size();i++)
-
{
-
m += list.get(i).toString();
-
}
-
MimeMessage message = new MimeMessage(session);
-
message.setRecipient(Message.RecipientType.TO,new InternetAddress(m));
-
Please help me,
But what you posted is not what your code looks like. Can you post the code that's giving you this error as it is?
P.S It's not a bad time to read something about Java scoping rules.
Hi,
I used the following code, -
ArrayList list = new ArrayList();
-
while(rs.next())
-
{
-
//String to=rs.getString(1);
-
list.add(rs.getString(1));
-
}
-
String m="";
-
for(int i=0;i<list.size();i++)
-
{
-
m += list.get(i).toString()+"," ;
-
}
-
//String to=m;
-
-
-
-
MimeMessage message = new MimeMessage(session);
-
message.setRecipient(Message.RecipientType.TO,new InternetAddress(m));
-
If I pass one mail id to database I got the correct answer, If I pass more than one mail ids , I got the following error,
ERROR.....javax.mail.internet.AddressException: Illegal address in string ``dev@gmail.com,anu@gmail.com,a@yaoo.com,b@yahoo.c om,''
If I pass like
message.setRecipient(Message.RecipientType.TO,new InternetAddress("a@yaoo.com","b@yahoo.com"));
I got the correct answer, How to split the mail ids like above, If I use split(",") or "," means , It does not support more than one mail id's.
Please give the solution.
Hi,
I used the following code, -
ArrayList list = new ArrayList();
-
while(rs.next())
-
{
-
//String to=rs.getString(1);
-
list.add(rs.getString(1));
-
}
-
String m="";
-
for(int i=0;i<list.size();i++)
-
{
-
m += list.get(i).toString()+"," ;
-
}
-
//String to=m;
-
-
-
-
MimeMessage message = new MimeMessage(session);
-
message.setRecipient(Message.RecipientType.TO,new InternetAddress(m));
-
If I pass one mail id to database I got the correct answer, If I pass more than one mail ids , I got the following error,
ERROR.....javax.mail.internet.AddressException: Illegal address in string ``dev@gmail.com,anu@gmail.com,a@yaoo.com,b@yahoo.c om,''
If I pass like
message.setRecipient(Message.RecipientType.TO,new InternetAddress("a@yaoo.com","b@yahoo.com"));
I got the correct answer, How to split the mail ids like above, If I use split(",") or "," means , It does not support more than one mail id's.
Please give the solution.
You can get an array of InternetAddress objects from using the parse method.
Hi,
Thank you very much for your help, Now Its work perfectly with multiple mailid's.
but In some other system its not working. my smtp settings like
props.put("mail.smtp.host","mail.companyname.com") ;
If I give the mailids like a@company.com,b@company.com means
its working proper, otherwise I give a@gmail.com,b@yahoo.com means I got the following error,
ERROR.....javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
class com.sun.mail.smtp.SMTPAddressFailedException: 500 Unauthorized relay msg rejected
Please help me,
thanks in advance.
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
2 posts
views
Thread by David C. Holley |
last post: by
|
2 posts
views
Thread by HairlipDog58 |
last post: by
|
1 post
views
Thread by Joep |
last post: by
|
8 posts
views
Thread by nescio |
last post: by
| | | | | | | | | | | | | | | |