When you send an email a header is part of the message. For example, when you check your mail you can view the raw source and see the headers, which has information about the sender of email in it, etc.

When I send mail using the mail command, from address1 to address2, the header includes some information about the sender, like sender's hostname, IP, etc.

Now my Question is: How is the information for the header generated, and how can I avoid or change them (i.e, forge them)?

I'm use Fedora 17 and Sendmail.

  • 2
    To avoid any confusion, you might want to clarify why you want to do this, just so people are aware that your intentions are ethical...
    – jasonwryan
    Commented Jul 2, 2012 at 19:09
  • 1
    I just want to know. because when I was sending mail using Yahoo Mail or Gmail, I thought that the page is doing this work, but now when I use this command or when I use my Java program to send mail, I see that these informations are generated again itself, now I want to know how these informations are made?
    – M0εiπ
    Commented Jul 2, 2012 at 19:13
  • 1
    The information (received headers) are typically inserted by each hop (mail server). Commented Jul 2, 2012 at 19:15
  • 1
    Every Mail Transport Agent (MTA, mail server) adds its own Received: header as it forwards the email to the next one — starting with your computer or nearest mail server and ending at the recipient's. Modifying them at the destination doesn't erase the trail of the email (MTAs keep logs), and I can't think of a single legitimate/ethical reason for changing existing Received: headers.
    – Alexios
    Commented Jul 2, 2012 at 20:28

1 Answer 1


The headers are initially generated by the Mail User Agent (MUA, i.e., your mail client) and contain very little information. It depends on the MUA being used, but will usually include at a minimum From, To, Subject and Date. Using the Unix mail command you can specify additional headers to be added with the -a flag.


mail -a "X-foo: bar" [email protected]

This will include a header X-foo with a value of bar. You can specify -a multiple times.

The message is then delivered to the Mail Transfer Agent (MTA, i.e., your SMTP mail server). The mail server will insert headers such as Received-from as it deems necessary into the message. The only way you can influence this is by controlling and configuring the server yourself.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .