How to use basic SMTP protocol for sending mail?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   gary_cheung
Posted On:   Wednesday, May 23, 2001 07:33 PM

How to use basic SMTP protocol for sending cc mail, attrachment mail.thank you.
please say to me detail or give me some source code.thank you

Re: How to use basic SMTP protocol for sending mail?

Posted By:   John_Zukowski  
Posted On:   Thursday, May 24, 2001 04:27 PM

Sending mail and using cc is already covered in the FAQ.

Re: How to use basic SMTP protocol for sending mail?

Posted By:   Yogesh_Sharma  
Posted On:   Wednesday, May 23, 2001 09:01 PM


import javax.servlet.*;
import javax.servlet.http.*;
import javax.mail.*;
import javax.activation.*;
import javax.mail.internet.*;
import java.sql.*;
import java.io.*;
import java.util.*;
public class javamail1 extends HttpServlet
{
PrintWriter pw=null;
String login="",to="",host="",cc="",bcc="",attach="",from="",subject="",message="";
String str="",str1="",str2="",str3="",str4="",str5="",main="",to1="",cc1="",bcc1="";
Vector vto=null,vcc=null,vbcc=null;
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException,IOException
{ try{
res.setContentType("text/html");
pw=res.getWriter();
to=req.getParameter("to");
cc=req.getParameter("cc");
bcc=req.getParameter("bcc");
subject=req.getParameter("subject");
message=req.getParameter("message");
vto=new Vector(5,1);
vcc=new Vector(5,1);
vbcc=new Vector(5,1);
from="navics5@yahoo.com";
host="mail.spectranet.com";
boolean sessionDebug=false;
StringTokenizer st=new StringTokenizer(to,",");
while(st.hasMoreTokens())
{
vto.addElement(st.nextToken());
}
StringTokenizer st1=new StringTokenizer(cc,",");
while(st1.hasMoreTokens())
{
vcc.addElement(st1.nextToken());
}
StringTokenizer st2=new StringTokenizer(bcc,",");
while(st2.hasMoreTokens())
{
vbcc.addElement(st2.nextToken());
}
InternetAddress address[]=new InternetAddress[vto.size()];
InternetAddress address1[]=new InternetAddress[vcc.size()];
InternetAddress address2[]=new InternetAddress[vbcc.size()];

Properties props=System.getProperties();
props.put("mail.host",host);
props.put("mail.smtp.host", "smtp.mail.yahoo.com");

Session session=Session.getDefaultInstance(props,null);
session.setDebug(sessionDebug);

Message msg=new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
for(int i=0;i {
to1 = (String)vto.elementAt(i);
address[i]=new InternetAddress (to1);
}
msg.setRecipients(Message.RecipientType.TO,address);


for(int i=0;i {
cc1 = (String)vcc.elementAt(i);
address1[i]= new InternetAddress(cc1);
}
msg.setRecipients(Message.RecipientType.CC,address1);

for(int i=0;i {
bcc1 = (String)vbcc.elementAt(i);
address2[i]= new InternetAddress(bcc1);
}
msg.setRecipients(Message.RecipientType.BCC,address2);

msg.setSubject(subject);
msg.setSentDate(new java.util.Date());

}
catch(Exception e){System.out.println(e);}
}






public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException,IOException
{
doPost(req,res);
}

}
About | Sitemap | Contact