简体   繁体   English

从<>空发件人地址发送电子邮件

[英]Send email from the <> null sender address

Send-MailMessage
 -From "from@example.com"
 -To "to@example.com"
 -Subject "Subject" `
 -SmtpServer "localhost" -Body "Test Message"

I'm sending email using Send-MailMessage , the powershell equivalent of using System.Net.Mail.MailMessage. 我正在使用Send-MailMessage发送电子邮件,这与使用System.Net.Mail.MailMessage的功能相同。

Is there any way of sending email from the null sender address? 有什么方法可以从空发件人地址发送电子邮件? If not are there any powershell/.NET alternatives I can use. 如果没有,我可以使用任何powershell / .NET替代方案。

From is required so cannot be omitted. 从是必需的,因此不能省略。 null, "" etc aren't acceptable because Send-MailMessage validates the from is an email address. null,“”等是不可接受的,因为Send-MailMessage验证from是电子邮件地址。


<> Null sender address : "The sender address is the email address that will receive email about delivery problems (mailing lists change this but not the From: email header so that they, and not the people sending to them, get messages about delivery problems). A special null sender address (MAIL FROM:<>) is used to signal that no one cares and no bounce notifications should be sent. Null senders are used when sending bounce messages themselves, and sometimes at other times." <>空的发件人地址“发件人地址是将接收有关投递问题的电子邮件的电子邮件地址(邮件列表会对此进行更改,但发件人:电子邮件标头不会更改,因此,他们(而不是发送给他们的人)会收到有关投递问题的消息)。使用特殊的空发件人地址(MAIL FROM:<>)表示没有人在乎,也不应发送退信通知。在自己发送退信消息时,有时在其他时间,将使用空发信人。”

You cannot do this with SmtpClient and MailMessage, so using this or Send-MailMessage is out of the question. 您无法使用SmtpClient和MailMessage进行此操作,因此无法使用它或Send-MailMessage。 Unfortunately that means you're left with either finding a third party library which does support it, or writing the code yourself to send directly through SMTP. 不幸的是,这意味着您要么找到一个支持它的第三方库,要么自己编写代码直接通过SMTP发送。

You're probably better off testing this part of your system with a unit test. 您最好使用单元测试来测试系统的这一部分。

Manually with telnet 使用telnet手动

open localhost 25

HELO Foo
MAIL FROM: <>   <--- the null address

Automated. 自动化。

Not actually the complete working code, but should give the general impression GetFile and SmtpStream are streams. 实际上并不是完整的工作代码,但应该给人以一般印象,GetFile和SmtpStream是流。 The solution is to feed an pre-created .eml file by directly interacting with the SMTP protocol. 解决方案是通过直接与SMTP协议进行交互来馈送预先创建的.eml文件。

        GivenAClientIsConnectedToAnAgentInTheWAITINGState();

        SmtpStream.WriteAsciiString("MAIL FROM:<>{0}", Environment.NewLine);
        SmtpStream.ReceiveAsAsciiString();

        SmtpStream.WriteAsciiString("RCPT TO:<{0}>{1}",mailboxAddress, Environment.NewLine);
        SmtpStream.ReceiveAsAsciiString();

        SmtpStream.WriteAsciiString("DATA{0}", Environment.NewLine);
        SmtpStream.ReceiveAsAsciiString();
        SmtpStream.SendEmail(_fileRepository.GetFile("NullSenderMessage.eml"));
        SmtpStream.SendDataTerminator();
        SmtpStream.ReceiveAsAsciiString();
        SmtpStream.WriteAsciiString("QUIT");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM