email with picture as an attachment

hi frndsis it possible in j2me to send an email with attachment(picture)if so give me some idea or code regarding the sameand if not help me with some work arroundalpesh
[204 byte] By [alpesha] at [2007-10-3 10:52:24]
# 1
HiOne idea would be to open a SocketConnection to your email smtp server, open an output stream, and write the image bytes directly into the body of the message. On the receiver side, you would have to re-compose the image from those bytes.Mihai
Printisora at 2007-7-15 6:17:53 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2

thanks Mihai

I tried SMTP for simple text messages first

problem is, I am receiving the mails but message body is empty

here is the code:

sc = (SocketConnection)Connector.open("socket://"+smtpServerAddress+":25");

is = sc.openInputStream();

os = sc.openOutputStream();

os.write(("HELO there" + "\r\n").getBytes());

os.write(("MAIL FROM: "+ from +"\r\n").getBytes());

os.write(("RCPT TO: "+ to + "\r\n").getBytes());

os.write("DATA\r\n".getBytes());

// stamp the msg with date

os.write(("Date: " + new Date() + "\r\n").getBytes());

os.write(("From: "+from+"\r\n").getBytes());

os.write(("To: "+to+"\r\n").getBytes());

os.write(("Subject: "+subject+"\r\n").getBytes());

os.write((msg+"\r\n").getBytes()); // message body

os.write(".\r\n".getBytes());

os.write("QUIT\r\n".getBytes());

alpesh

alpesha at 2007-7-15 6:17:53 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3
I can't see any error. Are ou sure you have something in the msg and it's not empty? Try printing the whole line ( (msg+"\r\n").getBytes() ) and see what you get.Mihai
Printisora at 2007-7-15 6:17:53 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4

hi Mihai

I did this and it's displaying the msg (before converting into bytes)

and also after converting msg into bytes i tried (msg+"\r\n").getBytes() and it displaying bytes means it is not null

also If I am sending mails to gmail or yahoo it gives me the error:

SMTP server response -

220 dnsconsultant (IMail 7.15 2462-1) NT-ESMTP Server X1

250 hello dnsconsultant

250 ok

550 not local host gmail.com, not a gateway

503 No recipient(s).

502 unimplemented command

502 unimplemented command

502 unimplemented command

502 unimplemented command

502 unimplemented command

502 unimplemented command

221 Closing connection. Good bye.

so if I want to send mails to/from any (yahoo, gmail and etc...) e-mail addresses what will be the smtpServerAddress

and is there any other configuraton needed?

alpesh

alpesha at 2007-7-15 6:17:53 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5
I don't know what the SMTP addresses are for GMail and Yahoo. You need to check that. Also some extra security might be needed, like authentication, You have to search a little for this.Mihai
Printisora at 2007-7-15 6:17:53 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 6
Also, try using with mail4ME and see if it works better for you; I think it supports MIME types and it hides all the low coding part from you.Mihai
Printisora at 2007-7-15 6:17:53 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 7
Obviously your trying to use a mailserver as a relay. This is always disables for spamming an other abuse.You'll need to send your email though a local smtp server, or use authentication.
deepspacea at 2007-7-15 6:17:53 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 8

thanks

I got you guys

my question is:

If I want to send an Image to an email address from an email address

solution:

I think no other way other than using smtp and all configurations as you have mentioned

but dont you think this is quite complecated process for front-end j2me application?

what I am thinking is I do an Http push with parameters like

(i) to email,

(II) from email and

(III) data, which contains Bytes of Image

and my back-end application will send e-mail as what i want

is it possible and doable and efficient?

alpesh

alpesha at 2007-7-15 6:17:53 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 9
Yes it is doable, and it's even more efficient, because you can send the image binary and not base64.
deepspacea at 2007-7-15 6:17:53 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 10
It is possible and is more efficient; you would have a thin client and a rich server-side which will manage the actual email sending. You would still need to deal with the authentication part.Mihai
Printisora at 2007-7-15 6:17:53 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 11
hi frndz thanks for helpI have started developing image bytes posting method,let me try, if any query i will raise my hand againonce againthanks !!!alpesh
alpesha at 2007-7-15 6:17:53 > top of Java-index,Java Mobility Forums,Java ME Technologies...