I am trying to create a simple ruby mail server ( SMTP server) just or fun. I tried the code in the http://snippets.dzone.com/posts/show/3932
I am not able to sendmail from my machine. I also posted comment there but no reply ;(.
Can any you please help me by giving a pointer or a simple ruby smtp server that can send mail to my gmail account without using a SMTP servers or MTA.
Your SMTP server still needs to connect to smtp.gmail.com to forward your mail. The protocol for doing so can be found in RFC821 (http://james.apache.org/server/rfclist/smtp/rfc0821.txt)
It looks like the example above just allows you to connect to the SMTP server on localhost and store mails locally.
Related
I was trying to understand if the SMTP virtual server in IIS can only relay mails or if it can act as the final SMTP server. All the tutorials I've found on how to configure it always show it acting as a relay.
It can delivery directly mails (SMTP Server) also relay them
On Mac, I can send email from command line using the command mail, but definitely I don't have SMTP server installed on my MacBookPro.
So, it is possible to send email with Ruby without an SMTP server? I don't care about the speed, I just want a way to send email without additional software needed.
You could just call the mail command from within your Ruby code. Use system or backticks or something more sophisticated like open3 to interact with system commands... Here is a nice overview over the different methods: http://mentalized.net/journal/2010/03/08/5_ways_to_run_commands_from_ruby/
About mail and sendmail
I don't know much about mail, but results from a quick search on Google seem to indicate that it uses postfix, which is the default SMTP server that is installed on Macs. In other words, you have installed and are running a SMTP server on your Macbook Pro.
About Ruby
So, it is possible to send email with Ruby without an SMTP server?
Yes and No. You don't need to have a SMTP server running on the same machine as your Ruby process. In fact, you don't even need to run your own SMTP server. However, you need a SMTP server somewhere to send your email.
About SMTP
This article on howstuffworks gives a good explanation of what SMTP does. Essentially, you need a SMTP server somewhere that accepts your email, talks to other SMTP servers, and passes your email on for delivery. With Ruby, you can configure Net::SMTP to connect to a SMTP server of your choice.
About What You Are Trying To Do
If you want to write and execute a script that will deliver a small number of email messages, create a fake email account on Gmail/Live and use their SMTP servers for sending email.
If you want to build and launch an app that will deliver emails to your users, use Mandrill, MailGun, or SendGrid. Mandrill has a free tier for you to get started.
I don't recommend running your own SMTP server for most use cases, because your emails will likely be marked as spam. (Comcast might also think that you have malware on your network.) Professional services like Mandrill will help you setup SPF and DKIM records to authenticate your emails and improve sending reputation.
(If you just want to test email in dev mode, use MailCatcher.)
Conclusion
Sign up for a Mandrill account, then use Net::SMTP in Ruby to connect to their SMTP servers. No additional software is required.
If your mail command is working, then you can send mail from within
ruby. And if your mail command is working on your mac already, then
you also already have an SMTP server working on your mac, since by
default it uses postfix which comes installed. The mail command
defaults to using /usr/sbin/sendmail, which is in this case an
interface to postfix. (Try man sendmail from the Terminal.)
Now, that said, you will probably experience something like this when trying to use Net::SMTP locally:
[3] pry(main)> smtp = Net::SMTP.start('localhost',25)
Errno::ECONNREFUSED: Connection refused - connect(2)
This means that you need to do something to tell your mac that it can
accept connections on port 25. Another alternative is to use that
sendmail program as a transport access method, which might actually be the
better option. The port 25 access is turned off so that no one else
can use your mac as a mail relay. Having to go through the sendmail
command means that only programs on your mac can send mail (go
figure).
My suggestion here would be to use the mail gem (or pony if you
prefer) and configure it to use sendmail. From the mail README
file:
Sending via sendmail can be done like so:
mail = Mail.new do
from 'me#test.lindsaar.net'
to 'you#test.lindsaar.net'
subject 'Here is the image you wanted'
body File.read('body.txt')
add_file :filename => 'somefile.png', :content => File.read('/somefile.png')
end
mail.delivery_method :sendmail
mail.deliver
Likewise, if you're using ActionMailer you can configure it to use
sendmail as well.
Have you tried the Pony gem? It provides a really simple interface to sendmail, which should already be installed on your Mac.
Is your goal to write and send email from the CLI?
There's a number of mailer gems, including mail. You could probably also play directly with Ruby's Net::SMTP and get something working, depending on what you are trying to do.
You don't have to have an SMTP server, you just need to know where one is that you can connect to.
See Net::SMTP. It's part of Ruby.
If you used mail or /usr/sbin/sendmail command and your mail delivered successfully, then there was an MTA (Mail/Message transfer Agent eg. postfix, sendmail or whatever) running on your machine.
when you use your mail command to send a mail to guser#gmail.com,your mail command will submit the mail to local SMTP server.
(local) SMTP server will do the following tasks.
SMTP server(MTA) will do MX lookup for gmail.com
Connect to port 25 of MX server and hand over the mail by talking SMTP (HELO, MAIL FROM,RCPT TO,DATA commands)
Mx server will deliver the mail to the corresponding mailbox (guser).
The above answers suggest you to use Net::SMTP where you will connect to some SMTP server and hand over the mail to that SMTP server, which will again do the above tasks (of local SMTP server above) to perform the delivery.
So to send mail, u need an SMTP server. or you will have to code yourself/use some library to perform MX lookup and hand over the mail to the MX server by talking SMTP commands as per RFC 2821.
I have two ruby on rails application on different servers. Both are working fine, but one (server 2) can't send any mails.
I got always the 554 5.7.1 : Relay access denied error.
On server 2 I tested the mail communication with the help of telnet and it works, but it doesn't works with the ruby on rails application.
Other application can send mails, too.
The only difference between both systems are the os (Debian 6 (server 1) and RHEL 6 (server 2)) and the ip ranges (10 network (server 2) and 53 network (server 1)).
I think the best way is to use a simple mail application, but I don't know, how to write something like that.
Thanks for any help.
The IP address of your second server is not in the whitelist for that email server, but the first one is.
Unless you're using authenticated SMTP, you will have to add the IP addresses of all your application servers to the whitelist configuration.
Using telnet will only tell you if the port is accepting connections, not if you can actually send email. For that you'll have to perform an actual SMTP transaction.
There are services like Postmark, SendGrid or even my start-up PostageApp which will act as a mail server for you.
I know how to test smtp email using telnet. But I think because telnet uses "its own channel" to reach smtp server, it doesn't necessarily mean the normal smtp communication on port 25 would work. (Please correct me if this is not true)
Basically the client has encountered with an issue : [ERROR] Access to default session denied during a test from application to reach smtp server. From the same server, telnet to send an email just works...
So I've got no other choice but to figure out why I am getting this sort of error. Done my research only to find out lots and lots of command-line email applications, no good in this case as it is the client's environment that I've got little control on what to install.
So I think the last resort would be using simple DOS commands? Please advise if there is even a better way. Many thanks in advance.
I know how to test smtp email using telnet. But I think because telnet uses "its own channel" to reach smtp server, it doesn't necessarily mean the normal smtp communication on port 25 would work.
That's incorrect. If sending e-mail works with typing it to the Windows telnet application, then it works, i.e. there is no problem with the SMTP server, and there are no firewall issues between the client and the server.
So the bug is most probably in the in the application displaying the error message. Maybe there is no bug, but the application is not configured properly.
I think because telnet uses "its own channel" to reach smtp server, it doesn't necessarily mean the normal smtp communication on port 25 would work. (Please correct me if this is not true)
That is not true. A "real" SMTP client uses the same method to talk to the SMTP server as telnet does.
If you do not trust Telnet, use Thunderbird, but the problem is probably with your client software or configuration. Double check the settings there and see if you can turn on any trace logging (on the client or the server).
I am trying to send mail from a local iis app using localhost as my smtp server after installing free smtp but I am getting the following error:
Mailbox unavailable. The server response was: Invalid
recipient: 'validAddress'#hotmail.com
Any idea what the problem could be?
it sounds like your free (3rd party) smtp app is not leaving your network and might be trying to see if it has that mailbox itself. Try and see if there is a setting to allow the smtp server to access external connections, etc. What is the name of the free smtp app, btw?
Alternatively, can u use the built in SMTP mail provider, built into iis? do you know how to use that, instead of this 3rd party app.
It looks more like the SMTP service needs to be configured to "Relay" email... Usually this involves telling it what YOUR mail domain is, and then any mail destin for a domain other than it's own will cause it to go out to the world, and try to relay the message to the real server.
But, be careful! This is how spammers exploit email servers. They look for SMTP listeners that will relay for them. You want to make sure yours will only accept relay mail from "localhost", or whatever machine will be connecting to it to do the sending.
A more secure way is to block port 25 inbound at your firewall to this box, so this SMTP server is not visible to the outside world.
Write and test a simple smtp sender in C. It needs 3 minutes with RFC
Use Wireshark to see what comes on the wire between your application and the SMTP server.