ProgramingTip

mail 명령을 사용하여 이메일을 보낼 때 보낸 사람을 지정합니다.

bestdevel 2021. 1. 9. 16:27
반응형

mail 명령을 사용하여 이메일을 보낼 때 보낸 사람을 지정합니다.


누구든지 메일 명령을 사용하여 이메일을 보낼 때 사용자를 변경하는 방법을 알고 있습니까? 나는 남자 페이지를 훑어마다 어떻게 하는지를 볼 수 없다.

Redhat Linux 5를 실행하고 있습니다.


http://www.mindspill.org/962 에 해결책이있을 것입니다.

본질적으로 :

echo "This is the main body of the mail" | mail -s "Subject of the Email" recipent_address@example.com -- -f from_user@example.com


-a로 필요한 추가 헤더를 사용할 수 있습니다.

$mail -s "Some random subject" -a "From: some@mail.tld" to@mail.tld

메일 -r from@from.from -R from@from.com

-r = 주소에서 -R = 주소에 답장

작성자는 자신의 메일 버전 이이 플래그를 지원하지 않는다고 표시했습니다. 그러나 이것은 작동하는 버전이 권한이 있습니다.


SMTP를 통해 통신 할 때 mailman 페이지는 다음과 같이 from변수 를 설정하도록 권장합니다 (CentOS 6에서 테스트 됨).

mail -s Subject -S from=sender@example.com recipient@example.com

다음 -a옵션을 사용하여 파일을 첨부 할 수도 있습니다 .

mail -s Subject -S from=sender@example.com -a path_to_attachement recipient@example.com

이들 중 어느 것도 나를 위해 일하지 배합 (Ubuntu 12.04) 이렇게 만들었습니다.

echo 'my message blabla\nSecond line (optional of course)' | 
mail -s "Your message title"
-r 'Your full name<yourSenderAdress@yourDomain.abc>'
-Sreplyto="yourReplyAdressIfDifferent@domain.abc"
destinatorEmail@destDomain.abc[,otherDestinator@otherDomain.abc]

(모두 한 줄에, "-Sreplyto"에 공백이 없음)

다음 에서이 메일 명령을 예배.

apt-get install mailutils

먼저-를 추가하여 메일 명령 끝에 sendmail 옵션을 추가 할 수 있습니다. -f는 보낸 사람 주소를 설정하기 위해 sendmail의 명령입니다. 따라서 다음과 같이 할 수 있습니다.

메일 recipient@foo.com--f sender@bar.com


여기에 해결책이 있습니다.

-r 다음의 두 번째로 쉬운 해결 방법 (From : 헤더를 지정하고 다음과 같이 개행 문자로 본문과 분리하는 것입니다)

 $mail -s "Subject" destination@example.com
 From: Joel <joel@example.com>

 Hi!
 .

몇 가지 메일 버전에서만 작동합니다. redhat이 어떤 버전을 가지고 있는지.)

추신 : 대부분의 메일 버전은 엉망입니다!


위의 어느 것도 나를 위해 일하지 않다. 그리고 그것을 알아내는 데 오랜 시간이 걸렸습니다. 이것이 다음 사람에게 도움이되기를 바랍니다.

mailutils v2.1과 함께 Ubuntu 12.04 LTS를 사용하고 있습니다.

나는이 솔루션을 인터넷 어딘가에서 찾았고 어디에서나 다시 수 없습니다.

-aFrom:Servername-Server@mydomain.com

사용 된 전체 명령 :

cat /root/Reports/ServerName-Report-$DATE.txt | mail -s "Server-Name-Report-$DATE" myemailadress@mydomain.com -aFrom:Servername-Server@mydomain.com

echo "This is the main body of the mail" | mail -s "Subject of the Email" recipent_address@example.com -- -f from_user@example.com -F "Elvis Presley"

또는

echo "This is the main body of the mail" | mail -s "Subject of the Email" recipent_address@example.com -aFrom:"Elvis Presley<from_user@example.com>"

대부분의 사람들은 이메일에서 보낸 사람 주소를 위조 할 때 두 가지 값을 변경해야합니다. 첫 번째는 보낸 사람 주소이고 두 번째는 원본 주소입니다. 온라인으로 제공되는 많은 솔루션은 이러한 가치 중 하나만 변경합니다.

루트로서 간단한 메일 명령을 사용하여 다음과 같은 전자 메일을 보냅니다. echo "test" | mail -s "a test" me@noone.com

관련 로그 : Feb 6 09:02:51 myserver postfix/qmgr[28875]: B10322269D: from=<root@myserver.com>, size=437, nrcpt=1 (queue active) Feb 6 09:02:52 myserver postfix/smtp[19848]: B10322269D: to=<me@noone.com>, relay=myMTA[x.x.x.x]:25, delay=0.34, delays=0.1/0/0.11/0.13, dsn=2.0.0, status=sent (250 Ok 0000014b5f678593-a0e399ef-a801-4655-ad6b-19864a220f38-000000)

보낸 사람 주소를 변경하려고 echo "test" | mail -s "a test" me@noone.com -- dude@thisguy.com

이렇게하면 원본 값이 변경 시작 값은 변경되지 않습니다. Feb 6 09:09:09 myserver postfix/qmgr[28875]: 6BD362269D: from=<root@myserver.com>, size=474, nrcpt=2 (queue active) Feb 6 09:09:09 myserver postfix/smtp[20505]: 6BD362269D: to=<me@noone>, orig_to=<dude@thisguy.com>, relay=myMTA[x.x.x.x]:25, delay=0.31, delays=0.06/0/0.09/0.15, dsn=2.0.0, status=sent (250 Ok 0000014b5f6d48e2-a98b70be-fb02-44e0-8eb3-e4f5b1820265-000000)

다음으로 -r 및 a-를 사용하여 시작 및 원본을 조정합니다. echo "test" | mail -s "a test" -r dude@comeguy.com me@noone.com -- dude@someguy.com

그리고 로그 : Feb 6 09:17:11 myserver postfix/qmgr[28875]: E3B972264C: from=<dude@someguy.com>, size=459, nrcpt=2 (queue active) Feb 6 09:17:11 myserver postfix/smtp[21559]: E3B972264C: to=<me@noone.com>, orig_to=<dude@someguy.com>, relay=myMTA[x.x.x.x]:25, delay=1.1, delays=0.56/0.24/0.11/0.17, dsn=2.0.0, status=sent (250 Ok 0000014b5f74a2c0-c06709f0-4e8d-4d7e-9abf-dbcea2bee2ea-000000)

이것이 나를 위해 일하는 방식입니다. 이것이 누군가를 돕기를 바랍니다.


이 Centos7에서 작동합니다.

echo "This is the main body of the mail" | mail -s "Subject of the Email" -r seneder_address@whatever.com recipent_address@example.com


2018 년 데비안 9에 대한 답변입니다.

메모 -e에코에 대한이 줄 바꿈 문자를 허용하고, -rmailx의에 대한 발신 이메일 주소와 함께 이름을 표시하기 :

$ echo -e "testing email via yourisp.com from command line\n\nsent on: $(date)" | mailx -r "Foghorn Leghorn <sender@yourisp.com>" -s "test cli email $(date)" -- recipient@somedomain.com

도움이 되었기를 바랍니다!


CentOs5 : -r from@me.omg


모든 예제 공급자 덕분에 일부는 그렇지 않은 경우도있었습니다. 아래는 나를 위해 일한 또 다른 간단한 예제 형식입니다.

echo "Sample body" | mail -s "Test email" from=sender-addrs@example.com recepient-addres@example.com

CentOS의 경우 여기에 작업 명령이 있습니다.

mail -s Subject -S from=sender@example.com recipient@example.com

나는 같은 문제에 직면했다. 하지만 문제는 / ect / passwd 필드 에 geko 필드를 설정하는 것뿐입니다 . Postfix는 기본적으로 사용자 로그인에서 메일을 보냅니다. 필드에서 경고로 변경한다고 가정 해 보겠습니다. 원하는 편집기에서 / ect / passwd 파일을 편집하기 만하면됩니다.

  1. 정력 / ect / passwd

root : x : 0 : 0 : 경고 : / root : / bin / bash

  1. postfix를 다시 시작하십시오.

이제 결과를 확인하십시오.

  1. echo "메일 본문입니다."| mail -s "이메일 제목"user@domain.com

이제받는 사람입니다. 보낸 사람 은 geko 필드에 지정한 대로 경고표시됩니다 . 이 솔루션이 효과가 있기를 바랍니다.

참조 URL : https://stackoverflow.com/questions/119390/specify-the-from-user-when-sending-email-using-the-mail-command

반응형