hi friends...
i m new in java mail api..so please identify and enlight the minor mistakes..
actually how much i know,,for sending a mail to a perticular address we require a mail server and an account in that mail server and then one can send an email from that perticular account to a valid another email account made in any mail server..am i right upto this??
i used an yahoo mail server to send mail from my own yahoo account and it is working fine..
as below the snippet .i m using ....."mymailid@yahoo.com"
public class Registrationform extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#HttpServlet()
*/
private static final String emailMsgTxt = "hi hwo r u??.";
private static final String emailSubjectTxt = " Confirmation Subject";
private static final String emailFromAddress = "santosh_ipsacademy10@yahoo.com";
// Add List of Email address to who email needs to be sent to
private static final String[] emailList = {"frndmailid@rediff.com", "mymailid@gmail.com"};
public Registrationform() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.println("<h1>Webmail</h1>");
SendMailUsingAuthentication smtpMailSender = new SendMailUsingAuthentication();
try{
smtpMailSender.postMail( emailList, emailSubjectTxt, emailMsgTxt, emailFromAddress);
}catch(MessagingException e){out.println(e);}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
class SendMailUsingAuthentication
{
private static final String SMTP_AUTH_USER = "santosh_ipsacademy10";
private static final String SMTP_AUTH_PWD = "password_of_this_account";
private static final String SMTP_HOST_NAME = "smtp.mail.yahoo.com";
public void postMail( String recipients[ ], String subject,
String message , String from) throws MessagingException
{
boolean debug = false;
// Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
System.out.println("mail sent");
}
private class SMTPAuthenticator extends javax.mail.Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(SMTP_AUTH_USER,SMTP_AUTH_PWD );
}
}
}
? i m making an mail application and i want to use an email address(from where i m sending mail) like this "mymailid@mychoice.com" not a predifined mail id like "mymailid@yahoo.com".
will i need a different mail server or i can achieve this with this server only what is ur opinion ??if it is possible then please write ur snippet if u would like or give me a brief idea..
? how it is possible to create an account with mail id like "mymailid@mychoice.com" in any mail server .not like "mymailid@yahoo.com" as if i m using yahoo mail server.
waiting for quick reply
thanks in adcance