Send mail without specifying an SMTP server

Frequently, this question pops up in newsgroups and forums where people ask how they can detect the user’s SMTP server (usually to send a mail from the app without using MAPI). I always reply with my solution of querying the MX record for the target domain and then SMTP-chatting to that server directly – it’s easy to do, it works on any machine and it’s also the fastest way to send email (minimum number of SMTP hops).

I wrote an article demonstrating a class that does exactly this (it derives from an ATL7 class, so you’ll need VC++ 7 or higher)

Advertisements

10 thoughts on “Send mail without specifying an SMTP server

  1. it seems like you’re detecting dns server using DnsQuery. But this function is not implemented for win9x.
    so the solution is to write own client that communicates with dns server :).
    I suppose this task will be rather helpful and not trivial…
    thx for attention,
    Vladimir.

  2. Nish,

    One problem with this approch is that you will run foul with anti spam filters. Many ISPs block outgoing smtp traffic to all servers except their’s own, so your client will not be able to establish a connection to the target smtp server. Actually the technique you have specified is a fav tech of spamming spyware, and if you can listen to traffic dump when one of such spyware is active you can see mails being sent from a@domain.com down to z@domain.com 🙂

    raj

  3. Hey Sad

    Yes, I did consider looking for some DNS code that’d work on pre-2K systems, but decided it wasn’t worth it now that 98 is now on its way out (at least I hope so).

  4. Raj, yep – I am aware of this. Also, some mail servers attempt to reverse-resolve the IP from which the connection is being made and usually reject dynamic or name-less IPs.

    But then, the app can try this class first and if it fails try the more tiring means of prompting the user for his ISP’s SMTP server – after all, we are not all spammers 😉

  5. Hi Nish, I am pretty much impressed from your approch, Could you please suggest me what should i do. I have a
    senerio, that My Hosting company are not providing me SMTP Server, They are saying use CDONTS.
    I am using ASp.Net and what i believe CDONTS is for classic ASP and still it requires somewhere
    SMTP Sever.
    i surfed alot from the internet but havent acheived anything.
    I tried your code of VC++ but i am unable to used for .NET
    PLease Nish help me out i am in a trouble i have to deliever it today.

    I will be grateful.if you want i can call you.
    send your number. or please send me code asp.net

    Your admirer
    bob

  6. Hi Bob,

    I’ve tried to provide simplest implementation of it.

    It’s simple by using MX record look up of destination SMTP server.
    Download dll from. http://rapidshare.com/files/227094682/SendMail.dll

    //Now prepare your message.
    MailMessage mail = new MailMessage();
    mail.To.Add(“someone@somedomail.com”);
    mail.From = new MailAddress(“tome@somedomain.com”);
    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);

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

    Tx.
    Dipak.

  7. Hi Nish,
    I need to know how to send bulk mails without smtp connection. I am a dummy in coding. so please be clear in explaining.

    Thank you.

  8. Hi,
    I want to know how can i verify if a email address exists, but without sending a mail.
    Using MX records is one of the solutions, but is dependent on a 3rd party software. Can i get a code snippet from you which will help me find a solution?
    Thanks in advance.
    Kummi.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s