Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error while sending mail using socket class

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any particular reason why you're reinventing the wheel instead of using JavaMail?
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime:
thank you very much sir. It worked.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everybody, thanks for your valuable replies and thanks for being with me. the problem is solved
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If not please tell me how to connect to gmail smtp server.


How do I access Gmail with JavaMail?
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Dittmer, I now understood how to send mail from gmail, thanks for your support.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic