Send email from Mac OS X via perl script - macos

I am trying to send email using a Perl script from my Mac, for which I have installed
MIME::Lite module. I am using a basic script to test:
#!/usr/bin/perl
use MIME::Lite;
$msg = MIME::Lite->new(
From =>"abc\#gmail.com",
To =>"xyz\#gmail.com",
Subject =>"Demo",
Data =>"Sent :-):-)"
);
$msg->send();
I have already set up my email account in my macbook.
Please guide me if I need something else to check for as i am unable to send the email.

Gone are the days when you could just use a system call out to the command line:
mail boss#megacorp.net -s "I QUIT!" < body_of_message.txt
But if you install and configure mutt to talk to your mail server, you can do something pretty close:
mutt -s "I QUIT" boss#megacorp.net < body_of_message.txt
The hardest bit is configuring mutt, and that's not too bad. There are a ton of docs and howtos out there, like Mutt Configuration Doc ...or just google for "mutt configure" and the type of mail server that you're using; gmail, exchange, etc.
From there, in perl, you would just:
system("/path/to/mutt", "-s", "I QUIT", "boss\#megacorp.net", ...)
or die "Could not send Email";

I haven't used this module but I note the docs for it say
MIME::Lite is not recommended by its current maintainer. There are a
number of alternatives, like Email::MIME or MIME::Entity and
Email::Sender, which you should probably use instead. MIME::Lite
continues to accrue weird bug reports, and it is not receiving a large
amount of refactoring due to the availability of better alternatives.
Please consider using something else.
http://metacpan.org/pod/MIME::Lite
Having said that, you may need to do something like
Specify default send method:
MIME::Lite->send('smtp','some.host',Debug=>0);
MIME::Lite->send('smtp','some.host', AuthUser=>$user, AuthPass=>$pass);

Related

Send email from command line with Ruby

I'm trying to send an email from the command line with Ruby code on a Sinatra server. On the command line, I've successfully used:
smtpfree_mail.pl -from noreply#website.com -to testemail#gmail.com -subject "test msg" -body "message body"
so could I possibly use:
%x(smtpfree_mail.pl -from noreply#website.com -to testemail#gmail.com -subject "test msg" -body "message body")
as suggested by this answer? I want to later input several variables into the email body.
Why don't you use mail sending gems such as mail or pony?
You can do it natively just right from your Sinatra application code.
I didn't suggest ActionMailer since it huge, these gems above are very small and handy.
Can you run other programs from Ruby? Yes, you can. As you have seen from the question you have linked to.
Having no idea what smptfree_mail.pl holds, it is perhaps not possible for you to later input several variables into the email body. Assuming that it is sending that e-mail out, I would suppose that changing the content of the e-mail body would be questionable, as it would be too late, the next mail server would have it and it would be out of your hands.
However, it would be possible for you to change the body of the message earlier, not later, and easily so, as you have the template code in your question that sets the stage.
you can use Net::SMTP its much more secure and you can pass variables please check this in rubydocs.
A working example/tutorial can be found here

Windows SendTo from script

I'm writing an application where I have to send an email with an attachment using the default mail application.
Before the email is sent, I want the user to be able to edit the text, i.e. the application should just open the mail client with pre-filled recipient and attachment and give the user the opportunity to send it.
At very minimum I need the same effect I'd got if I selected "SendTo/Mail Recipient" from the context menu of the file.
Solutions based on the "mailto:" trick won't work as there are mail clients that do not support the "attachment=" part.
The most complete solution I've found is this one:
http://www.codeproject.com/Articles/3839/SendTo-mail-recipient
but it seems a lot of code for something so simple! (and also crashes when compiled with VS2008)
Is there any other option? It would be ok even if it was an external tool or script (e.g. a .vbs script to be launched with cscript).
I would advise you to use MAPI (Messaging Application Program Interface).
If dotNet can be part of the solution, here's a ready-to-use class in C# : Class for creating MAPI Mail Messages. It would give you something like this:
MapiMailMessage message = new MapiMailMessage("Test Message", "Test Body");
message.Recipients.Add("Test#Test.com");
message.Files.Add(#"C:\del.txt");
message.ShowDialog();
Otherwise, you can always do it in C++ if you feel confortable with it, like this answer suggest.
Then, you will be able to ShellExecute the binary executable and pass it some parameters.
Hope this helps :-)

Open mail client from cli ruby script like a mailto link

I have written a ruby cli script which takes a CSV and generates a PDF report, based on said CSV. I'm fairly new to Ruby, so while it's probably not the greatest code, I'm pretty proud of what I've made.
At any rate, what I would really like to do now, is make my script email said PDF as an attachment. I'm sure there is a library that understands SMTP and can send this on my behalf, but I would like to modify the email body, and review the attachments before sending. So it seems like the simplest thing would be to have the script start a new email in my system default mail client, providing the recipient, subject, and boiler plate text, and attaching the generated file, kind of like a mailto: link in a web page (does mailto support attachments?).
Seems like there could be a system command that does this, completely unrelated to Ruby, which I could have my Ruby script call. That would be fine. If it's platform dependent, I'm on OSX, but I move around, so am interested in Windows and Linux solutions, too.
I guess plan B would be a way to jam a simple CLI editor into my Ruby script, to let me edit the email text, and then use an SMTP library to send the email. That seems harder, unless it's already been done.
Actually you can execute any ruby file from command-line interface (CLI) using console_runner gem. If you already have written code you can run it from command line. All you need is to add annotations (YARD-like syntax) to your Ruby code and then execute it from command line:
$ c_run /path/your_file.rb say_hello
/path/your_file.rb:
# #runnable
class MyClass
# #runnable
def say_hello
puts 'Hello!'
end
end

Simple AppleScript to export Apple Mail messages to FileMaker DB?

I'm using a product called "Mail Archiver X" to archive messages from Apple Mail into a custom FileMaker database ("eMailViewerX" - this is the target database that comes with Mail Archiver and is required for the process), from where I copy these messages to my main message archive (another FileMaker DB).
While that process works, it is kind of clumsy (Apple Mail > Mail Archiver X > FileMaker DB #1 > FileMaker DB #2) - and it breaks every time when there is a new version of Apple Mail or OS X until "Mail Archiver X" has been updated by the developer.
So I'm looking for a more simple solution: an AppleScript that will export all messages from exactly one folder ("To Archive") in Apple Mail (4.5/Snow Leopard or 5.0/Lion) as a simple CSV or .tab file, with the following data per line:
Message Sender*
Message Receiver*
Sent Date
Sent Time
Subject
Body
(* Separation of name and e-mail address would be cool, but I understand this may not (always) be possible.)
The only tricky part may be the conversion of carriage returns in the e-mail messages' body into the special character FileMaker expects in TAB or CSV files. In BBEdit, this is shown as \x{0B} (UTF8: 0B). So there would have to be a Find/Replace for that in the script.
No interface, no configuration - just something that spits out all messages from a folder and tells me when it's done.
This does not have to be free (although I wouldn't mind :) - I'd gladly pay for something reliable and simple.
If someone knows about such a script or is willing to write it, I would really appreciate it. I haven't found anything.
TL;DR: I need to export all messages from an Apple Mail folder to a FileMaker-readable CSV file.
There is software called Mail to Filemaker Importer, it's less than $20.
Is this an IMAP mailbox? If so you could use a plugin and download the messages directly into FileMaker records.

Running Pine/Alpine within a Windows PowerShell

I am attempting to move most of my daily working life to a terminal shell. I am a .NET dev so I run on WinXP purely for visual studio (just wait until I get better at Emacs). I would really much like it if I could use an email client within a terminal (either using Console or PowerShell within Console).
From my uni days I know of only pine and so this is what I tried to get for windows. However, I could only find two variants, PC-Pine and Alpine for Windows. Both of these provide the mail functions I want and they can connect to my domain exchange server BUT I cannot get them to launch with the shell I am using (Console with PowerShell).
My question: Is there anyone out there running Windows that uses a console mail client that can run in PowerShell or Console2 which has the same or similar functionality to Pine?
If you want to READ email from either the Windows CMD line or Powershell, your best bet it to try and get one of the UNIX-style Terminal email clients to work using CGYWIN as the front end. You might want to try MUTT or the Softabar CMD EMail Client but I haven't tried either one myself.
However, if all you want is SEND email, then that's easy :)
I use Powershell to send emails using the following snippit. This could very easily be put into a script or pasted into your $Profile file to allow you to send emails on the fly.
$emailFrom = "sender"
$emailTo = "recipient"
$subject = "Your subject"
$body = "Your Message"
$smtpServer = "smtp.server.com"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
You could even wrap this in a "Send-Mail" cmdlet and call it using the parameters whenever you want, for example Send-Mail("ivan#stackoverflow","dbarrett83#stackoverflow","I answered your question","Hey man, answered you question on SO...go check it out. 'n. Talk to you later - Dan"). Just make sure to use 'n (the accent key under the tilde followed by the lowercase 'n') for line breaks.
I hope this helps!
~Dan

Resources