in reply to Sending email from excel by one click

To add in excel a body and a subject in the mail link, append the mail address with an attribute part like this in Excel:

=(Hyperlink("Mailto:me@home.com?Subject=Emailing From Excel&Body=This +is a test"))

Some fragments that could be handy if you want to send the mail directly with perl.

If you want to read excel file to obtain the emails given inside.

use Spreadsheet::Read; #use only for simply excel files # take the filename from commandline and try to take in the excel file my $file1 = ReadData ($excelfile); # obtain the last line on the first sheet my $max_row1 = $file1->[1]{maxrow}; # loop through the rows for (my $i; $i <= $max_row1; $i++) { # read the name on the cell A $i my $name = $file1->[1]{cr2cell ( 1, $i)}; # read the file on the cell B $i my $file = $file1->[1]{cr2cell ( 2, $i)}; }

To compose an email with perl.

use MIME::Lite; my $from_address = 'me@home.com'; my $out_server = 'out.home.com'; my $subject = "subject"; my $body = <<"MAIL"; blabla MAIL my $document = 'some data' #open and put data into this my $filename = 'see above' ### Create a new multipart message: my $msg = MIME::Lite->new( From => $from_address, To => $email_address, Subject => $subject, Type => 'multipart/mixed' ); ### Add parts (each "attach" has same arguments as "new"): $msg->attach( Type => 'TEXT', Data => $body ); $msg->attach( Type => $mime_type, Data => $document, Filename => $file, Disposition => 'attachment' ); ### use Net:SMTP to do the sending. Depends on your system what to use +. eval {$msg->send('smtp', $out_server);}; # via a outbound mailserver eval {$msg->send();}; # sending via local send command on linux system

have a nice day

Martell

Replies are listed 'Best First'.
Re^2: Sending email from excel by one click
by pavan6754 (Initiate) on May 25, 2011 at 19:09 UTC

    Thanks a lot Martell.. for detail explanation.. :)

    i want to with first option.. as user will have control over the email which he is sending( i.e he can add other users or extend body..etc )

    Now my Question.. can we have variables in the body (i.e using Hyper LInk),as i want to put cell values in the body

    Thanks

      Normally you can. Simply use the concatenation function '&' in excel. For example:

      =(Hyperlink("Mailto:me@home.com?Subject=" & A3 & "&Body=" & A2 & "Kind + regards"))

      This will put the content of cell A3 in the subject and A2 into the body.

      Search in google on: 'excel mailto body' for other examples.

      Kind Regards

      Martell