• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • Paul Clapham
  • Rob Spoor
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
Bartenders:

java.mail without specifying SMTP server

 
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to write code to send email without trying to specify the SMTP server.
I have tried DOS nslookup without success. On the other hand, it may be impossible and the SMTP server is not in the computer, I just don't know.

Your help will be greatly appreciated,

Alejandro Barrero
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to run your own mail server for testing, you can use the James open source Java server. I have used it for years, it doesn't require a whole lot of memory to run.

Bill
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bill. James definitely offers a solution; I just downloaded it and will start examining it in short detail. However, my code will be in an application that I will distribute; if I use mail, I will have to include James in the installation of the application. Searching further in the Internet I found Aspirin which appears to be an embeddable SMTP server. I am going to move in the direction of Aspirin and similar before I go for James.
Still, it should be possible to execute Dos commands to find the SMTP server.
 
Rancher
Posts: 4804
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand your request. The user has to setup the computer's applications to know the SMTP server, which is specified by the ISP or network administrator. I've never seen how a program can detect this. It could search for all possible mail clients, and snoop on their settings, but that may be hard to do in general and transportable.

Can you try rephrasing your request?

The answer of "use this mail package" seems over kill to me. All you need is the name of the host servicing SMTP (and maybe POP or IMAP)
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I would like to do, if it is possible, is to write code that can send email by specifying only the sender, the receiver, the topic and the contents.
I hope this is clear.
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found in another forum, a solution that is technically correct:

But now the users of my program would have to have gmail addresses. I am going to continue looking.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alejandro Barrero wrote:I want to write code to send email without trying to specify the SMTP server.
I have tried DOS nslookup without success. On the other hand, it may be impossible and the SMTP server is not in the computer, I just don't know.

Your help will be greatly appreciated,

Alejandro Barrero



Hi,

it's simple by using MX record look up of destination SMTP server.
Download dll from. removed, may be harmful

//Now prepare your message.
MailMessage mail = new MailMessage();
mail.To.Add("[email protected]");
mail.From = new MailAddress("[email protected]");
mail.Subject = "Send email without SMTP server";
mail.Body = "Yep, its workin!!!";

//Send message
string domain = mail.To[0].Address.Substring(mail.To[0].Address.IndexOf('@') + 1);
//To Do :need to check for MX record existance before you send. Left intentionally for you.
string mxRecord = SendSMTP.DnsLookUp.GetMXRecords(domain)[0];
SmtpClient client = new SmtpClient(mxRecord);
client.Send(mail);

Have look at http://dvgoswami.googlepages.com/ for complete details.


Done!

Tx.
Dipak.
 
Sheriff
Posts: 22883
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dipak,

I removed your post yesterday on purpose, for the following reasons:

1) you kicked a 10 month old thread: http://faq.javaranch.com/java/DontWakeTheZombies
2) you posted the exact same post last month in https://coderanch.com/t/416571/Other-JSE-JEE-APIs/java/we-will-Develop-Send-Email
3) your post links to a DLL that can do god knows what

If you still want to post your links, this is the place to go.
reply
    Bookmark Topic Watch Topic
  • New Topic