• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

error while sending mail using socket class

 
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob Prime:
thank you very much sir. It worked.
 
chaitanya karthikk
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Dittmer, I now understood how to send mail from gmail, thanks for your support.
 
If you live in a cold climate and on the grid, incandescent light can use less energy than LED. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic