From: "M. A. Alves" <maa@liacc.up.pt>
To: comp.lang.ada@ada.eu.org
Subject: Re: Looking for package Email
Date: Mon, 18 Jun 2001 17:44:23 +0100 (WEST)
Date: 2001-06-18T17:44:23+01:00 [thread overview]
Message-ID: <mailman.992879123.15466.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: <3B2E17E2.4755E820@raytheon.com>
> [1] On many systems, generate your mail message as a text file & use an
> OS call to run your mail utility program to send it.
Doing that now. Using the "mail" utility on a Linux system, in a call to
the POSIX "system" function. Simplest way, I think. It works---as long
as the system settings associated with the "mail" utility are ok of
course.
package Mail is
Error: exception;
procedure Send_Message(
To: String;
CC: String := "";
BC: String := "";
Reply_To: String := "";
Subject: String := "";
Text: String := "");
end Mail;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_Io; use Ada.Text_Io;
with Posix; use Posix;
package body Mail is
procedure Send_Message(
To: String;
CC: String := "";
BC: String := "";
Reply_To: String := "";
Subject: String := "";
Text: String := "")
is
Tempfilename: String := "/tmp/a_temporary_mail_message_text_file";
Tempfile: File_Type;
U: Unbounded_String;
R: Integer;
begin
Create(Tempfile, Out_File, Tempfilename);
Put(Tempfile, Text);
Append(U, "mail");
if CC /= "" then
Append(U, " -c" & CC);
end if;
if BC /= "" then
Append(U, " -b" & BC);
end if;
if Subject /= "" then
Append(U, " -s """ & Subject & """");
end if;
Append(U, " " & To & " < " & Tempfilename);
R := System(To_String(U));
Delete(Tempfile);
if R = 127 or R = -1 then raise Error; end if;
end Send_Message;
end Mail;
package Posix is
function System(Command: String) return Integer;
end Posix;
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
package body Posix is
function C_System(Command: chars_ptr) return int;
pragma Import(C, C_System, "system");
function System(Command: String) return Integer is
C_Command : aliased char_array := To_C(Command);
begin
return(Integer(C_System(To_Chars_Ptr(C_Command'Unrestricted_Access))));
end System;
end Posix;
--
,
M A R I O data miner, LIACC, room 221 tel 351+226078830, ext 121
A M A D O Rua Campo Alegre, 823 fax 351+226003654
A L V E S P-4150 PORTO, Portugal mob 351+939354002
next prev parent reply other threads:[~2001-06-18 16:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-06-18 15:08 Looking for package Email M. A. Alves
2001-06-18 13:17 ` Gerhard Häring
2001-06-18 15:01 ` Mark Johnson
2001-06-18 16:34 ` Samuel Tardieu
2001-06-18 16:44 ` M. A. Alves [this message]
2001-06-19 8:45 ` Ken Thomas
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox