Re: Changing "mail from"

2017-06-04 Thread Wietse Venema
> Mail is sent to m...@mynoc.eu and forwarder to m...@streamservice.nl.
> In that case I want the mail from to be m...@mynoc.eu, I don't
> care about the original address in the mail from during the SMTP
> stage. Every other location where the original mail address is
> listed doesn't have to be changed (eg in the mail headers including
> the "From" line).

It's a bad idea, but you could do it with a Milter.  Extract the
recipient from the MTA-to-Milter SMFIC_RCPT command, and send that
in the Milter-to-MTA SMFIR_CHGFROM request. And do something sensible
if a message has more than one recipient.

The problem is that it changes the error reporting address in a way
that breaks error reporting; if m...@streamservice.nl has a delivery
error, mail will loop between m...@mynoc.eu and m...@streamservice.nl.

You might just as well specify the null sender in the SMFIR_CHGFROM
request, or add "NOTIFY=NEVER" to the SMFIR_CHGFROM request.

Wietse


Re: idn or smtputf8 ?

2017-06-04 Thread Wietse Venema
Benny Pedersen:
> how do i get forward solving this ?

Specify both the xn--mumble and UTF8 forms in Postfix configuration
files. As documented Postfix does not automatically convert table
lookup requests.

Wietse


Re: Sending e-mails using postdrop - possible ?

2017-06-04 Thread Kent
Hi Wietse,

Thanks for your guidance so far.

I'm trying to use the postfix sendmail command line - and have this working 
(code is still rough).   However, I'm now trying to get any output from the 
command.

To simulate an error, I've intentionally added an invalid -N option - which in 
my manual testing outputs an error about invalid option.

Below is my c code - I can't get the error back in my buffer.  Can you have a 
look at let me know if there's anything obvious I'm doing.

thanks

Kent.


--
int sendMail ( std::string from, std::string to, std::string message )
{
int ret_code = -1;

// /usr/sbin/sendmail.postfix -f 'from@email.address' -N 'success, 
delay, failure' 'to@email.address' < tmp

const char * exec_path = prefs_PostfixUnixPath().c_str();   // 
/usr/sbin/sendmail.postfix 
std::string _f; _f.assign("-f "); _f.append( from );// -f 
email@address.domain

char * child_args[] = {(char *)"-N 'success,delay,failure,invalid'", 
(char *)_f.c_str(), (char *)to.c_str(), NULL};

int pid;
int pc[2]; /* Parent to child pipe */
int cp[2]; /* Child to parent pipe */
char ch;

/* Make pipes */
if( pipe(pc) < 0)   {   log_write("Can't make pipe: pc");   
return -1;  }
if( pipe(cp) < 0)   {   log_write("Can't make pipe: cp");   
return -1;  }


// The 'SIGCHLD' signal is triggered when the child fork completes - we 
want to ignore this.
signal(SIGCHLD,SIG_IGN);
// ignore 'SIGCHLD' signal


/* Create a child to run command. */
switch( pid = fork() )
{
case -1: 
log_write("Error: Can't fork");
return -1;
case 0:
// === 
Child ===
close(1);   
// Close current stdout.
dup2( cp[1], 1 );   
// Make stdout go to write end of pipe.
close(2);
dup2( cp[1], 2 );   
// Make stderr go to write end of pipe.
close(0);   
// Close current stdin.
dup( pc[0] );   
// Make stdin come from read end of pipe.

close( pc[1] ); 
// Close what we don't need.
close( cp[0] );

printf("Execute: %s\n", exec_path );

execve( exec_path, child_args, NULL);

printf("Error: execve failed"); // this 
will only occur if 'execve' had an error.
exit(1);

default:
// === 
Parent ===

// Close what 
we don't need.

// the 'pipe' buffer size can vary - let's 
write in 1Kb chunks.  if 'out' == 0, buffer is full - wait and write again.
int out = write( pc[1], message.c_str(), 
message.length() );// write the message to postfix... (this is the 
whole from:, To:, Subject, Body, etc.)


close(pc[1]);   
// close once written
close(cp[1]);

int status = 0;
char buffer[1024];  
// Space to store the response 
- is 1Kb enough ???
int L = 0;
do {
waitpid(pid, &status, 0);
printf("PID Status: %d\n", status );

printf("\nOutput from child:\n");
while( read(cp[0], &ch, 1) == 1)
// read the reply

Re: Sending e-mails using postdrop - possible ?

2017-06-04 Thread Kent
Hi Wietse,

Further to below - after more testing I am getting errors, but not warnings.  I 
don't know where they are going, but I'm not getting them back at all.

eg.  If I call:
> /usr/sbin/sendmail.postfix -g
> sendmail.postfix: invalid option -- 'g'
> sendmail.postfix: invalid option -- 'g'
> sendmail.postfix: fatal: usage: sendmail.postfix [options]

Then, I do get these errors in my application buffer.

However, if I instead call:
> /usr/sbin/sendmail.postfix -N 'success,delay,failure,invalid' -f 
> k...@kamar.nz k...@test.kamar.kiwi.nz
> sendmail.postfix: warning: unknown DSN NOTIFY command value "invalid" in 
> "success,delay,failure,invalid"
> sendmail.postfix: warning: bad -N option value -- ignored

Then, I don't get these back in either STDOUT or STDERR

I can live with this - as ultimately it doesn't stop the e-mail from being sent.


cheers

Kent.



> Hi Wietse,
> 
> Thanks for your guidance so far.
> 
> I'm trying to use the postfix sendmail command line - and have this working 
> (code is still rough).   However, I'm now trying to get any output from the 
> command.
> 
> To simulate an error, I've intentionally added an invalid -N option - which 
> in my manual testing outputs an error about invalid option.
> 
> Below is my c code - I can't get the error back in my buffer.  Can you have a 
> look at let me know if there's anything obvious I'm doing.
> 
> thanks
> 
> Kent.
> 
> 
> --
> int sendMail ( std::string from, std::string to, std::string message )
> {
>   int ret_code = -1;
>   
>   // /usr/sbin/sendmail.postfix -f 'from@email.address' -N 'success, 
> delay, failure' 'to@email.address' < tmp
> 
>   const char * exec_path = prefs_PostfixUnixPath().c_str();   // 
> /usr/sbin/sendmail.postfix 
>   std::string _f; _f.assign("-f "); _f.append( from );// -f 
> email@address.domain
> 
>   char * child_args[] = {(char *)"-N 'success,delay,failure,invalid'", 
> (char *)_f.c_str(), (char *)to.c_str(), NULL};
> 
>   int pid;
>   int pc[2]; /* Parent to child pipe */
>   int cp[2]; /* Child to parent pipe */
>   char ch;
> 
>   /* Make pipes */
>   if( pipe(pc) < 0)   {   log_write("Can't make pipe: pc");   
> return -1;  }
>   if( pipe(cp) < 0)   {   log_write("Can't make pipe: cp");   
> return -1;  }
> 
> 
>   // The 'SIGCHLD' signal is triggered when the child fork completes - we 
> want to ignore this.
>   signal(SIGCHLD,SIG_IGN);
> // ignore 'SIGCHLD' signal
> 
> 
>   /* Create a child to run command. */
>   switch( pid = fork() )
>   {
>   case -1: 
>   log_write("Error: Can't fork");
>   return -1;
>   case 0:
>   // === 
> Child ===
>   close(1);   
> // Close current stdout.
>   dup2( cp[1], 1 );   
> // Make stdout go to write end of pipe.
>   close(2);
>   dup2( cp[1], 2 );   
> // Make stderr go to write end of pipe.
>   close(0);   
> // Close current stdin.
>   dup( pc[0] );   
> // Make stdin come from read end of pipe.
>   
>   close( pc[1] ); 
> // Close what we don't need.
>   close( cp[0] );
>   
>   printf("Execute: %s\n", exec_path );
>   
>   execve( exec_path, child_args, NULL);
>   
>   printf("Error: execve failed"); // this 
> will only occur if 'execve' had an error.
>   exit(1);
>   
>   default:
>   // === 
> Parent ===
>   
> // Close what 
> we don't need.
>   
>   // the 'pipe' buffer size can vary - let's 
> write in 1Kb chunks.  if 'out' == 0, buffer is full - wait and write again.
>   int out = write( pc[1], message.c_str(), 
> message.length() );// write the message to postfix... (this is 
> the whole from:, To:, 

Re: Sending e-mails using postdrop - possible ?

2017-06-04 Thread Wietse Venema
Kent:
> Hi Wietse,
> 
> Thanks for your guidance so far.
> 
> I'm trying to use the postfix sendmail command line - and have
> this working (code is still rough).   However, I'm now trying to
> get any output from the command.

In case of error it returns an exit status as defined in
/usr/include/sysexits.h. This is common UNIX practice/

Wietse


Re: Sending e-mails using postdrop - possible ?

2017-06-04 Thread Kent
Hi Wietse,

Thanks - as per my last e-mail,  I am getting the errors back.  It's just the 
warnings I'm not getting back.

But, I can live with this as the warnings will be my coding errors - so apart 
from my test with intentional issues, it hopefully shouldn't happen.


cheers

Kent.


> On 5/06/2017, at 10:16 AM, Wietse Venema  wrote:
> 
> Kent:
>> Hi Wietse,
>> 
>> Thanks for your guidance so far.
>> 
>> I'm trying to use the postfix sendmail command line - and have
>> this working (code is still rough).   However, I'm now trying to
>> get any output from the command.
> 
> In case of error it returns an exit status as defined in
> /usr/include/sysexits.h. This is common UNIX practice/
> 
>   Wietse



Re: Sending e-mails using postdrop - possible ?

2017-06-04 Thread Wietse Venema
Kent:
> Hi Wietse,
> 
> Thanks - as per my last e-mail,  I am getting the errors back.
> It's just the warnings I'm not getting back.

If you are concerned about mistakes, sendmail command line is not
the whole story. There is a lot more that can go wrong.

The MAILLOG file has a complete(*) record of successful and
unsuccessful deliveries, including warnings that did not result
in failure.

http://www.postfix.org/DEBUG_README.html#logging

Wietse

(*) modulo system-xxx-d rate limiting, but you still have a
choice of operating systems.