How to change sender name (not email address) when using the linux mail command for autosending mail? [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
Mailbox shows the sender name as "Apache", because the mail I am autosending is being sent from a Perl CGI program. How do I change it to something else?

You just need to add a From: header. By default there is none.
echo "Test" | mail -a "From: Someone <someone#example.com>" other#example.com
You can add any custom headers using -a:
echo "Test" | mail -a "From: Someone <someone#example.com>" \
-a "Subject: This is a test" \
-a "X-Custom-Header: yes" other#example.com

mail -s "$(echo -e "This is the subject\nFrom: Paula <johny#paula.com>\n
Reply-to: 1232564#yourserver.com\nContent-Type: text/html\n")"
milas.josh#gmail.com < htmlFileMessage.txt
the above is my solution..just replace the "Paula" with any name you want e.g Johny Bravo..any extra headers can be added just after the from and before the reply to...just make sure you know your headers syntax before adding them....this worked perfectly for me.

You can use the "-r" option to set the sender address:
mail -r me#example.com -s ...
In case you also want to include your real name in the from-field, you can use the following format
mail -r "me#example.com (My Name)" -s "My Subject" ...

If no From: header is specified in the e-mail headers, the MTA uses the full name of the current user, in this case "Apache". You can edit full user names in /etc/passwd

It depends on what sender address you are talking about. The sender address visble in the recipients mailprogramm is extracted from the "From:" Header. which can probably easily be set from your program.
If you are talking about the SMTP envelope sender address, you can pass the -f argument to the sendmail binary. Depending on the server configuration you may not be allowed to do that with the apache user.
from the sendmail manpage :
-f <address>
This option sets the address of the envelope sender of a
locally-generated message (also known as the return path).
The option can normally be used only by a trusted user, but
untrusted_set_sender can be set to allow untrusted users to
use it. [...]

On Ubuntu 14.04 none of these suggestions worked. Postfix would override with the logged in system user as the sender. What worked was the following solution listed at this link --> Change outgoing mail address from root#servername - rackspace sendgrid postfix
STEPS:
1) Make sure this is set in /etc/postfix/main.cf:
smtp_generic_maps = hash:/etc/postfix/generic
2) echo 'www-data yourusername#yourdomain.com' >> /etc/postfix/generic
3) sudo postmap /etc/postfix/generic
4) sudo service postfix restart

Related

I have a pcap with two MPLS headers . i observe the match criteria for every field in both the MPLS headers are similar . How do I differentiate? [closed]

Closed. This question is not about programming or software development. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 months ago.
The community reviewed whether to reopen this question 3 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I have a pcap with two MPLS headers . i observe the match criteria for every field in both the MPLS headers are similar . How do I differentiate between the two MPLS headers ? Is it possible to achieve this via Wireshark or tshark ? If it is possible to achieve via tshark , please share the linux cmd.
For example , i am trying to filter using -
mpls.exp==7 && mpls.bottom == 0
but with the above match filter criteria , even those packets where mpls.exp==7 (in header1) and mpls.bottom==0 (in header 2) are matched. Attaching pcap snip for your reference.
above match criteria matching exp from header 1 and bottom of stack from header 1
above match criteria matching exp from header 2 and bottom of stack from header 1
TIA.
Tried to filter this using tsahrk in linux . Still not able to get the desired result -
Expected result - only the first 8 packets only should be matched
Observed result - 16 packets are matched
Tshark cmd :
tshark -r capture2_11-17-2022_11-15-15.pcap -T fields -E header=y -e mpls.exp -e mpls.bottom mpls.bottom==0 and mpls.exp==7
tshark output table
2nd EDIT: I thought of an alternative solution, which I'll now describe here. (Note that I would have provided this alternative solution, which involves programming in the form of a Lua script, as a separate answer, but it seems folks were a little trigger-happy in closing this question, so I have no choice but to supply it here. If the question is reopened, which I've voted to do, I can make this a separate answer.)
What you can do is create an MPLS Lua postdissector that adds new mpls_post.exp and mpls_post.bottom fields to an MPLS postdissector tree. You can then use those new fields in your filter to accomplish your goal. As an example, consider the following Lua postdissector:
local mpls_post = Proto("MPLSPost", "MPLS Postdissector")
local pf = {
expbits = ProtoField.uint8("mpls_post.exp", "MPLS Experimental Bits", base.DEC),
bottom = ProtoField.uint8("mpls_post.bottom", "MPLS Bottom of Label Stack", base.DEC)
}
mpls_post.fields = pf
local mpls_exp = Field.new("mpls.exp")
local mpls_bottom = Field.new("mpls.bottom")
function mpls_post.dissector(tvbuf, pinfo, tree)
local mpls_exp_ex = {mpls_exp()}
local mpls_bottom_ex = {mpls_bottom()}
if mpls_exp_ex == nil or mpls_bottom_ex == nil then
return
end
local mpls_post_tree = tree:add(mpls_post)
mpls_post_tree:add(pf.expbits, mpls_exp_ex[1].range, mpls_exp_ex[1].value)
mpls_post_tree:add(pf.bottom, mpls_bottom_ex[1].range, mpls_bottom_ex[1].value)
end
register_postdissector(mpls_post)
If you save this to a file, e.g. mpls_post.lua and place that file in your Wireshark Personal Lua Plugins directory, which you can find from "Help -> About Wireshark -> Folders" or from tshark -G folders, then [re]start Wireshark, you will be able to apply a filter such as follows:
mpls_post.exp==7 && mpls_post.bottom == 0
You can also use tshark to do the same, e.g.:
tshark -r capture2_11-17-2022_11-15-15.pcap -Y "mpls_post.exp==7 && mpls_post.bottom==0" -T fields -E header=y -e mpls_post.exp -e mpls_post.bottom
(NOTE: The tshark command, as written, will simply print out what you already know, namely 7 and 0, so presumably you want to print more than just that, but this is the idea.)
I think this is probably the best that can be done for now until the Wireshark MPLS dissector is modified so that layer operators work as expected for this protocol, but there are no guarantees that any changes to the MPLS dissector will ever be made in this regard.
EDIT: I'm sorry to say that the answer I provided doesn't actually work for MPLS. It doesn't work because the MPLS dissector is only called once and it then loops through all labels as long as bottom of stack isn't true, but it doesn't call itself recursively, which is what would be needed in this case in order for the second label to be considered another layer. The layer syntax does work for other protocols such as IP (in the case of tunneled traffic or ICMP error packets) and others though, so it's a good thing to keep in mind, but unfortunately it won't be of much use for MPLS, at least not in the Wireshark MPLS dissector's current state. I suppose I'll leave the answer up [for now] in case the dissector is ever changed in the future to allow for the layer syntax to work as one might intuitively expect it to work. And unfortunately, I can't think of an alternative solution to this problem at this time.
With Wireshark >= version 4.0, you can use the newly introduced syntax for matching fields from specific layers. So, rather than specifying mpls.exp==7 && mpls.bottom == 0 as the filter, which matches fields from any layer, use the following syntax instead, which will only match against fields from the first layer:
mpls.exp#1 == 7 && mpls.bottom#1 == 0
Refer to the Wireshark 4.0.0 Release Notes for more details about this new syntax as well as for other display filter changes, and/or to the wireshark-filter man page.
NOTE: You can also achieve this with tshark, although you can't [yet] selectively choose which field is displayed. For example:
tshark -r capture2_11-17-2022_11-15-15.pcap -Y "mpls.exp#1 == 7 && mpls.bottom#1 == 0" -T fields -E header=y -e mpls.exp -e mpls.bottom
To be clear, you can't [yet] specify -e mpls.exp#1 and -e mpls.bottom#1.

Bash mail script which asks recipient, subject and body [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have a problem trying to make my own bash mail script which every time will ask to enter a recipient, subject and body in console. And then send it. Could anyone help with this? Thanks a LOT!
P.S I am using mail command
read -p "What is your subject ? " subj
read -p "What is your message? " mess
read -p "What is the recipient address? " add
grep -E '[[:alnum:]]+#[[:alnum:]]+(.[[:alnum:]]+){1,2}' <<< $add
if [[ "$?" == "0" ]
then
echo "$mess" | mail -s "$subj" $add
else
echo "ERROR - The recipient address is in the wrong format"
fi
Here we read in responses for subject, body and recipient we then check for the correct format of the email address and use the variables to send a mail if the recipient address is in the correct format. If not, show an error message.
You will use the read command to get user input. Hint: use the -p option.
Don't forget to "quote" all your variables, especially with variables holding unknown user input.

How to fill in a Command Line Interface?

I am to automate the installation phase of a legacy system, because I do not want to put more efforts again and again when ever I want to install it. During the installation process on Linux Terminal, I have to answer some questions regarding the basic configurations. Indeed, it is easy to automate the shell commands by putting them all in a batch file like the following:
bin/startServer destination/sub_v1
bin/startAdminInterface
....
However, I do not know how to automate the answers of a specific questions like the following:
Enter the server's IP address:
Enter the email of the contact person:
Would you like to disable UDP services?(y/n) [n]:
....
Is there any tool or programming language can deal with this situation? or Is there any way to pass the answers as a parameters within the batch file?
Thanks in advance.
The classic Linux tool for this job is expect.
With expect one can expect different questions and variations on a question, and the question does not have to be typed exactly. expect does not blindly answer every prompt, but rather it provides answers to the questions actually asked.
Here is a short example:
#!/usr/bin/expect -f
spawn someScript.sh
expect "Enter the server's IP address:"
send "10.0.0.4\r"
expect "Enter the email of the contact person:"
send "foo#bar.com\r"
expect "Would you like to disable UDP services?(y/n) [n]:"
send "y\r"
So, imagine this is a simplified version of the script:
#!/bin/bash
read -p "Enter something:" thing
read -p "Enter server IP:" ip
read -p "Enter Email:" email
echo Received $thing, $ip, $email
and this is in a file called answers
thingywhatnot
11.12.33.240
bozo#brains.com
You would run
installationScript < answers
and it would print this
Received thingywhatnot, 11.12.33.240, bozo#brains.com

How to whitelist recipients before mail goes to spamassassin?

I've been looking everywhere for a solution but didn't find.
What I need is to whitelist some recipient addresses so they won't ever go to the spamassassin filtering.
In my master.cf in postfix I have this:
spamassassin unix - n n - - pipe
user=spamd argv=/usr/bin/spamc -f -e
/usr/sbin/sendmail -oi -f ${sender} ${recipient}
Thanks in advance.
From https://spamassassin.apache.org/full/3.4.x/doc/Mail_SpamAssassin_Conf.html
whitelist_to user#example.com
If the given address appears as a recipient in the message headers (Resent-To, To, Cc, obvious envelope recipient, etc.) the mail will be whitelisted. Useful if you're deploying SpamAssassin system-wide, and don't want some users to have their mail filtered. Same format as whitelist_from.
There are three levels of To-whitelisting, whitelist_to, more_spam_to and all_spam_to. Users in the first level may still get some spammish mails blocked, but users in all_spam_to should never get mail blocked.
The headers checked for whitelist addresses are as follows: if Resent-To or Resent-Cc are set, use those; otherwise check all addresses taken from the following set of headers:
To
Cc
Apparently-To
Delivered-To
Envelope-Recipients
Apparently-Resent-To
X-Envelope-To
Envelope-To
X-Delivered-To
X-Original-To
X-Rcpt-To
X-Real-To
Open this file:
/etc/spamassassin/local.cf and add this line:
whitelist_from abc#def.com
That will whitelist the address. To blacklist an address just use
blacklist_from abc#def.com
Also, I'm running Ubuntu, and they also include a file in the same location,
65_debian.cf. You can add that there as well.
Make sure this plugin is uncommented:
ifplugin Mail::SpamAssassin::Plugin::Shortcircuit
whitelist_from abc#def.com
...
endif
All your whitelist/blacklist rules along with custom scores and rules should fall within these lines.

Postfix transport - invoke script after receive mail [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Debian Sid, latest postfix from Sid.
I need to invoke bash script after user reveive mail. So, what I did:
create file /etc/postfix/transport, for example:
mail#domain.com myscript
run command to create database: postmap transport
add to main.cf: transport_maps = hash:/etc/postfix/transport
add to master.cf: myscript unix - n n - - pipe user=michal flags=FR argv=/home/michal/test.sh
reload postfix
What's the problem? If I configure it this way, after mail is received, script "test.sh" will be executed, but incoming mail will not be delivered to mailbox and it will be deleted immediatelly after receiving.
So - how to avoid this? I need the script to be executed, but incoming mail should be also delivered to my mailbox.
Use Procmail.
:0c
| $HOME/test.sh
The script receives the full message on standard input, but if you don't feel like parsing the message yourself, there are standard techniques for extracting header values into Procmail variables. You can pipe to formail:
SUBJECT=`formail -zcxSubject:`
or you can grab into MATCH, which avoids spawning an external process, but is a bit trickier for more-complex tasks;
:0
* ^Subject:[ ]*\/.+
{ SUBJECT=$MATCH }
(the whitespace inside [ ] should be a space and a tab); either way, you can now pass in $SUBJECT as a parameter on the test.sh command line. Obviously, other header values can be extracted into variables in a similar way.
PS. You cannot inline the formail call like this because it will consume the standard input from the pipe.
:0c
| $HOME/test.sh "`formail -zcxSubject:`" # erroneous!
Instead, you need to split it up, like this:
:0
* ^Subject:[ ]*\/.+
{ SUBJECT=$MATCH }
:0c
| $HOME/test.sh "$SUBJECT"

Resources