Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Servlets
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Servlets section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 14th, 2004, 06:15 AM
Authorized User
 
Join Date: Sep 2004
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default mail with attachment in JAVA

I want to send a mail with attachment in JAVA.
Pl help me out
:)

rekha
__________________
It is always safe to assume, not that the old way is wrong, but that there may be a better way...
*************************
Rekha
 
Old September 16th, 2004, 04:26 AM
Authorized User
 
Join Date: Jul 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to sherbir
Default

Quote:
quote:Originally posted by rekha_jsr
 I want to send a mail with attachment in JAVA.
Pl help me out
:)

rekha
Hi Rekha,
If u have knowledge of Java Class APIs, I suggest using the JavaMail API and the Jakarta Commons FileUpload class for ur mission.

Hope this helps !!

Keep me posted.

Regards,
Sherbir
 
Old September 20th, 2004, 04:10 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 345
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to gokul_blr Send a message via Yahoo to gokul_blr
Default

<%

'First, initialize the JMail program...

Set JMail = Server.CreateObject("JMail.Message")

'Next, define your SMTP server & port address...
'(note that you just need to use the following line

JMail.ISOEncodeHeaders = False

JMail.From = "[email protected]"
JMail.FromName = "Test Message"

'The Subject property allows you to fill in the subject of the
'e-mail message you're sending...

JMail.Subject = "This is a Test of JMail"

'To add recipients to the e-mail message, you use the AddRecipient
'method. Note that it does not require the use of an = sign!

JMail.AddRecipient Request.Form("Email")

'You can keep adding recipients until you're done...
'JMail.AddRecipient "[email protected]"
'JMail.AddRecipient "[email protected]"
' Get the recipients mailbox from a form (note the lack of an equal sign).
'JMail.AddRecipient Request.Form("Email")
'You can also add recipients to what would normally be the CC:
'and BCC: fields of your e-mail, as follows (respectively)...
'JMail.AddRecipientCC "[email protected]"
'JMail.AddRecipientBCC "[email protected]"
'If you want to make the To: address more personal, you can
'use the AddRecipientEx method to add not only the person's
'e-mail address, but their name, too...
'JMail.AddRecipientEx "[email protected]", "Sparky O'Malley"
'The body of your message can be set in a number of ways. To
'set the body explicitly, you can just do something like this...

JMail.Body = "This is a test Email from a J-Mail Script."

'Or you might need to add text later after a generic greeting,
'in which case you'd append text to the body like this...

JMail.Body = JMail.Body & " Have a nice day!"

'You can also append text with the AppendText method...again,
'note the lack of an = sign here because you're using a method,
'not setting a property
'JMail.AppendText "Have a nice day!"
'If you have some text stored in a file, you can also use the
'contents of that file to set the body of the message, as
'follows...
'JMail.AppendBodyFromFile "c:\webserver\yourdomain\htdocs\mytext.txt"
'If your message is really important, you may want to set the
'message priority with the Priority property. When setting this
'property, remember that 1 is highest priority (urgent) and
'5 is lowest priority...

JMail.Priority = 1

'You can even add attachments to your message. As with the
'AddRecipient method, this does not use = signs and can be called
'as many times as you have attachments...
'JMail.AddAttachment "c:\webserver\yourdomain\htdocs\pix\myphoto.jp g"
'JMail.AddAttachment "c:\webserver\yourdomain\htdocs\faq\faq1.txt"
'Once you've set everything up, it's just a matter of sending the
'message...

JMail.Send(Request.Form("SMTP"))

%>



 
Old September 20th, 2004, 04:12 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 345
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to gokul_blr Send a message via Yahoo to gokul_blr
Default

JMail Example
The following example sends a plain-text email that contains an attachment.

<%
    ' Declare Variables
    Dim objJMail, strFilePath
    ' Get absolute path for file we want to attach to email.
    strFilePath = Server.MapPath("files/eternal-youth.pdf")
    ' Create instance of JMail Object
    Set objJMail = Server.CreateObject("JMail.SMTPMail")
    ' JMail SMTP on server
    objJMail.ServerAddress = "mail.gimmick-prodo.co.uk"
    ' JMail ContentType
    objJMail.ContentType = "text/plain"
    ' Senders email address
    objJMail.Sender = "[email protected]"
    ' Senders name
    objJMail.SenderName= "Gimmick Productions Ltd"
    ' Recipients email address
    objJMail.AddRecipient("[email protected]")
    ' Email Priority (3 = Normal)
    objJMail.Priority = 3
    ' Email Title
    objJMail.Subject = "Discover the secret to eternal youth"
    ' Email Body
    objJMail.Body = "Send $50 and we'll send you the secret to eternal youth!"
    ' Attach file to email
    objJMail.AddAttachment(strFilePath)
    ' Send Email
    objJMail.Execute()
    ' Close JMail Object and Destroy it to release memory
    objJMail.Close()
    Set objJMail = Nothing
%>In the above example, the Server object's MapPath method is used to return the absolute path for the file to attach.

For an HTML-based email, the ContentType property would have a value of "text/html" and the content of the Body property would contain HTML mark-up.



 
Old September 23rd, 2004, 02:06 AM
Authorized User
 
Join Date: Sep 2004
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your reply, But I need java code i have only java 1.3 installed on my server

rekha
 
Old September 23rd, 2004, 02:34 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

As a previous poster said, you need the JavaMail API which you can get at

http://java.sun.com/products/javamail/

There was a sample app included with the version I downloaded, there is a java forum dedicated to JavaMail at

http://forum.java.sun.com/forum.jsp?forum=43

There are tutorials available also.

 
Old September 23rd, 2004, 11:16 PM
Authorized User
 
Join Date: Jul 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to sherbir
Default

Quote:
quote:Originally posted by rekha_jsr
 Thanks for your reply, But I need java code i have only java 1.3 installed on my server

rekha
Hey rekha, that's asking for spoon feeding.
Well I recently developed an application in JSP to implement mass mailing.

I cannot post the code here as it's confidential.

However, I can mail u the code at ur email id if u wish 2 have it immediately. Give me a reminder at [email protected].

Else, u can go through the coding given at the java.sun.com's explanation of the JavaMail API. It has extensive details of using the API including the MIME-attachment part.

Keep me posted.

Cheers !!


Regards,
Sherbir
 
Old September 27th, 2004, 01:57 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 345
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to gokul_blr Send a message via Yahoo to gokul_blr
Default

I hope the sample codes are much more enough to proceed with



Quote:
quote:Originally posted by rekha_jsr
 Thanks for your reply, But I need java code i have only java 1.3 installed on my server

rekha
Gokulan Ethiraj
 
Old March 10th, 2006, 07:39 AM
Registered User
 
Join Date: Mar 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello rekha

u can seen more information about sending email and attachment
http://www.vipan.com/htdocs/javamail.html

jagat singh
(software engineer)
[email protected]







Similar Threads
Thread Thread Starter Forum Replies Last Post
Mail attachment surendran PHP How-To 0 August 3rd, 2006 06:05 AM
mail-attachment sureshdev786 General .NET 0 December 27th, 2004 09:34 AM
How to Send Mail with attachment using JAVA rekha_jsr Classic ASP Basics 2 September 16th, 2004 01:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.