Wednesday, July 1, 2009

Automatic Mail Generation From Ruby Code

I need to send a mail in between my program and need to add a file as an attachment.
so for accomplishing this task we nee to require some file as follows:

now we need to send mail for this we are going to use SMTP server.
so first we need to connect with the server through your domain name and port no.

and don't forget to start the smtp server after creating an object.

now almost done just prepare your mail header.
i have used mailfactory rather to use hard code header.
mailfactory is a gem.

Now the mailfactory object creation and creation of email header:

after creating the object we just need to kick off the object through SMTP server.

don't forget to destroy smtp object and close the connection.

so guys enjoy sending a mail through your code.
cheers!!!