|
-
October 6th, 1999, 03:44 PM
#1
Email Attachments
Hi All,
I am writing a email program that allows attachments. Using sockets to send the emails. The program is failing in case of Microsoft based products like word and powerpoint. It is working fine for text & HTML files. Any suggestions to fix this are welcome. The code for the attachments is given below
Thanks
Bhanu
public void SendMessage(HttpServletRequest request,HttpServletResponse response,ServletOutputStream Sout,String StrFileMailName,String StrAddressMail,String StrDataMail,String StrSubjectMail,String StrFromMail ,int IntCount)throws IOException
{
ServletOutputStream sout = response.getOutputStream();
Socket Sock = null;
PrintStream writer = null;
DataInputStream reader = null;
String StrDisp ="";
String SubStr ="";
int Int;
String Str = "";
String StrLine = "";
String StrData = "";
int PORT_NUMBER = 25;
String STR_HOST = ""; //I have the IP address here
String STR_HELO = "HELO "; // the server name is given here
String STR_MAIL_FROM = "MAIL FROM:<";
String STR_RCPT_TO = "RCPT TO:<";
String STR_DATA = "DATA";
String STR_QUIT = "QUIT";
String StrUserId = "";
String StrEmailId = "";
String StrAdminEmailId = "";
tring StrGetPath = "\\netscape\\suitespot\\docs\\upload/"; //attachment //location
try
{
Sock = new Socket(STR_HOST , PORT_NUMBER );
reader = new DataInputStream(new BufferedInputStream(Sock.getInputStream()));
writer = new PrintStream(new BufferedOutputStream(Sock.getOutputStream()));
writer.println(STR_HELO);
writer.flush();
StrDisp = reader.readLine();
/*****setting to, subject etc.**/
........
.......
if(!StrFileMailName.equals("Junk")) //checking if attachment is valid
{
try
{
File f = new File(StrFileMailName);
StrFileName = f.getName();
String StrNameFile = StrGetPath + StrFileName ;
File fTest = new File(StrNameFile);
BufferedReader instream = new BufferedReader(new FileReader(fTest));
Str = "----- \nContent-Type: application/octet-stream; name=" + "\"" + StrFileName + "\" \nContent-Transfer-Encoding: quoted-printable \n" ;
//Str = "----- \nContent-Type: application/vnd.ms-word; name=" + "\"" + //StrFileName + "\" \nContent-Transfer-Encoding: base64 \n" ;
//this option did not work.
Str += "Content-Disposition: attachment; filename=" + "\"" + StrFileName + "\" \n" ;
writer.println(Str);
writer.flush();
//reading the file characters one by one
int ch = 0;
sb = new StringBuffer("");
try
{
while( (ch = instream.read()) != -1)
{
sb.append((char) ch);
}
}
catch(Exception e)
{
sout.println(e.getMessage());
FlagTest = 1;
}
instream.close();
}
catch(Exception e)
{
sout.println(e.getMessage());
}
if(FlagTest == 0)
{
StrData = sb.toString();
Str = StrData ; // "This is a message for testing the file... \n";
writer.println(Str);
writer.flush();
}
}
Str = "------- \n";
writer.println(Str);
writer.flush();
StrDisp = reader.readLine();
Str = ".";
writer.println(Str);
writer.flush();
StrDisp = reader.readLine();
Str = "QUIT";
writer.println(Str);
writer.flush();
StrDisp = reader.readLine();
Sock.close();
}
catch(Exception ex)
{
sout.println(ex.getMessage());
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|