MAILFROM variable
For personal reasons I needed a way to set the sender address for mails send by cron.
I read that some cron versions support a MAILFROM variable for this purpose (https:/
I therefore wrote a patch for the current xenial cron package to support this variable.
diff --from-file cron-3.0pl1.orig cron-3.
103c103,104
< owner of the crontab.
---
> owner of the crontab. If MAILFROM is defined (and non-empty), it will be used
> as the envelope sender address, otherwise, ''root'' will be used.
diff --from-file cron-3.0pl1.orig cron-3.
81a82,100
> /* Check for arguments */
> static char* check_env_
> {
> if (argument) {
> const char *end;
>
> /* These chars have to match those cron_popen()
> * uses to split the command string */
> argument += strspn(argument, " \t\n");
> end = argument + strcspn(argument, " \t\n");
> if (*argument == '-' || *end != '\0') {
> printf("Bad Mailto/Mailfrom karma.\n");
> log_it(
> argument = NULL;
> }
> }
> return argument;
> }
>
132c151
< char *usernm, *mailto;
---
> char *usernm, *mailto, *mailfrom;
155a175
> mailfrom = env_get("MAILFROM", e->envp);
158,171c178,180
< if (mailto) {
< const char *end;
<
< /* These chars have to match those cron_popen()
< * uses to split the command string */
< mailto += strspn(mailto, " \t\n");
< end = mailto + strcspn(mailto, " \t\n");
< if (*mailto == '-' || *end != '\0') {
< printf("Bad Mailto karma.\n");
< log_it(
< mailto = NULL;
< }
< }
<
---
> mailto = check_env_
> mailfrom = check_env_
>
532a542,545
> // get name of sender
> if (mailfrom && !*mailfrom)
> mailfrom = NULL;
>
561c574,578
< fprintf(mail, "From: root (Cron Daemon)\n");
---
> if (mailfrom) {
> fprintf(mail, "From: %s\n", mailfrom);
> } else {
> fprintf(mail, "From: root (Cron Daemon)\n");
> }
It has been tested on Ubuntu 16.04 in conjunction with the ssmtp package to send the mail.
Not setting MAILFROM, setting it to "" and setting a valid mail worked for my purposes.
I'll just leave this here
Question information
- Language:
- English Edit question
- Status:
- Expired
- For:
- Ubuntu cron Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply: