aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes error while sending mail using socket class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "error while sending mail using socket class" Watch "error while sending mail using socket class" New topic
Author

error while sending mail using socket class

chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

hi everybody, i am chaitanya. i wrote a code which will connect to the yahoo smtp server and post a mail to the destination.

first i tried it using telnet from command prompt. i was a success. i thought to send an email through my java program. so i wrote this code.



each time we send a message to the server it replies with some numbers such as 220 250 334 as success proceed.
while sending the mail we have to get authenticated with the server. we have to send our mail id and password in base64 format. while i am sending my id to the server in base 64 format i am getting the reply as

----------451 Invalid Smtp line - Should end with CRLF

please help me.


Love all, trust a few, do wrong to none.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

1) use code tags
2) The error is pretty clear; lines should end in CRLF, which is short for carriage return + line feed, or \r\n. You are using only \n.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42643
    
  65
Is there any particular reason why you're reinventing the wheel instead of using JavaMail?


Ping & DNS - my free Android networking tools app
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

ulf dittmer:
sir i have jscape api. with that i can send a mail. but i want to do it on my own. that is the only reason.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

rob prime:
sir i used \n in the previous statements. it worked. but the third time it is not working. sir i will try with \r\n and i will inform you soon. thank you sir for your quote
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Rob Prime:
thank you very much sir. It worked.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Rob Prime:
i had sucessfully sent the mail. now i have a doubt. can i send an attachment using this procedure.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

hi everybody, thanks for your valuable replies and thanks for being with me. the problem is solved
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

You will need to go through the entire SMTP protocol, and see how attachments should be added. I can tell you this: it involves creating a multipart email, and adding the attachment in decoded form (usually Base64) as part of the email body. I'm sorry to say I cannot help you on how to do that without using JavaMail.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Rob Prime:
Thank you sir, I too understood the problem in sending mail without using JavaMail API. Now I am using JavaMail API, instead of opening a socket via telnet.

But i have a problem there too. I am able to connect to yahoo smtp server. but when I am trying to connect to gmail smtp server and trying to authenticate the gmail server is sending an error report to me. It is asking me to issue a 'starttls' command.

After issuing starttls command the server is not responding.

I have read in a forum that telnet does not support starttls, for that i have to download an application called stunnel.

What I have observed is that JavaMail API is using telnet in background to send mails. As telnet is not supporting starttls, JavaMail API is not able to connect to gmail smpt server. Am I right sir? If not please tell me how to connect to gmail smtp server.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42643
    
  65
If not please tell me how to connect to gmail smtp server.


How do I access Gmail with JavaMail?
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Thank you Dittmer, I now understood how to send mail from gmail, thanks for your support.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: error while sending mail using socket class