{"id":3170,"date":"2012-06-16T06:15:40","date_gmt":"2012-06-16T04:15:40","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=3170"},"modified":"2016-09-09T10:36:57","modified_gmt":"2016-09-09T08:36:57","slug":"send-email-without-smtp-server-dns-lookup","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/send-email-without-smtp-server-dns-lookup","title":{"rendered":"Send email without SMTP Server (DNS Lookup)"},"content":{"rendered":"<p>This tutorial shows the algorithm of DNS lookup in Mail.dll <a href=\"\/mail\">email component<\/a>,<br \/>\nwhich enables your application to send email without using your SMTP server.<\/p>\n<p>In general, you should send email via specified SMTP server. You may ask: how does the specified SMTP server know what address this email should be sent to? The answer is simple: it <strong>queries MX record<\/strong> of recipient&#8217;s domain using DNS lookup. It then forwards this email to the SMTP server queried from DNS server. <\/p>\n<p>If the recipient&#8217;s server doesn&#8217;t work fine or rejects the message, your SMTP server will send you an email to tell there was a failure in sending this email.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/wp-content\/uploads\/2012\/06\/send_email_1.png\" alt=\"\" title=\"Send email\" width=\"682\" height=\"292\" class=\"alignnone size-full\" \/><\/p>\n<p>You can however remove the first step and just <strong>ask DNS MX record for the recipient&#8217;s SMTP server yourself<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/wp-content\/uploads\/2012\/06\/send_email_2.png\" alt=\"\" title=\"Send email with recipient's SMTP\" width=\"428\" height=\"292\" class=\"alignnone size-full\" \/><\/p>\n<p>You do this by using <em>DnsHelper<\/em> helper class:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C# \r\n\r\nusing Limilabs.Client.DNS;\r\nusing Limilabs.Client.SMTP;\r\nusing Limilabs.Mail;\r\nusing Fluent = Limilabs.Mail.Fluent;\r\n\r\nstring receipientSMTP = new DnsHelper().GetSmtpServer(&quot;pat@recipient.com&quot;);\r\n\r\nusing(Smtp client = new Smtp())\r\n{\r\n   client.Connect(receipientSMTP, 25);\r\n   IMail email = Fluent.Mail.Text(&quot;Hello&quot;)\r\n       .From(&quot;john@your_domain.com&quot;)\r\n       .To(&quot;pat@recipient.com&quot;)\r\n       .Create();\r\n   client.SendMessage(email);\r\n   client.Close();\r\n}\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nImports Limilabs.Client.DNS\r\nImports Limilabs.Client.SMTP\r\nImports Limilabs.Mail\r\nImports Fluent = Limilabs.Mail.Fluent\r\n\r\nDim receipientSMTP As String = New DnsHelper().GetSmtpServer(&quot;pat@recipient.com&quot;)\r\n\r\nUsing client As New Smtp()\r\n\tclient.Connect(receipientSMTP, 25)\r\n\tDim email As IMail = Fluent.Mail.Text(&quot;Hello&quot;) _\r\n\t\t.From(&quot;john@your_domain.com&quot;) _\r\n\t\t.&#x5B;To](&quot;pat@recipient.com&quot;) _\r\n\t\t.Create()\r\n\tclient.SendMessage(email)\r\n\tclient.Close()\r\nEnd Using\r\n<\/pre>\n<p>Notice that we are using port 25. SMTP in plain text mode usually works on two ports: 587 &#8211; client STMP port, the one that is used by parameter-less <em>Connect<\/em> method and port 25 &#8211; used by servers (previously also used by clients). <\/p>\n<p>Client port (587) may be disabled on servers advertised by MX DNS records &#8211; those must use port 25 and are not required to allow clients to connect.<\/p>\n<p>There are two important things you should be also aware:<\/p>\n<ul>\n<li>This procedure is <strong>not<\/strong> what is popularly known as relaying.<\/li>\n<li>\nMost likely your IP address (the one from which you connect) does not designate a permitted sender for the sender&#8217;s domain (your domain, and yours domain MX record). This means that recipient&#8217;s SMTP server may refuse the message or can treat such message as spam.\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows the algorithm of DNS lookup in Mail.dll email component, which enables your application to send email without using your SMTP server. In general, you should send email via specified SMTP server. You may ask: how does the specified SMTP server know what address this email should be sent to? The answer is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[81,33,50],"class_list":["post-3170","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-dns","tag-email-component","tag-smtp"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/3170"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=3170"}],"version-history":[{"count":19,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/3170\/revisions"}],"predecessor-version":[{"id":5071,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/3170\/revisions\/5071"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=3170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=3170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=3170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}