[英]Sending email to address not set
I have this code 我有这个代码
var mail = new MailMessage(
"from@from.com",
"to@to.com",
"subject",
"body");
mail.ReplyToList.Add(new MailAddress("from@from.com"));
var client = new SmtpClient();
client.Send(mail);
In my web.config file I have 在我的web.config文件中
<system.net>
<mailSettings>
<smtp from="no-reply@no-reply.com">
<network host="smtp.live.com" password="mypassword" port="587" userName="myemailaddress@hotmail.com" enableSsl="true" />
</smtp>
</mailSettings>
</system.net>
The problem is this: The to address of the email that gets sent to to@to.com is not from@from.com but instead is myemailaddress@hotmail.com . 问题是这样的:发送到to@to.com的电子邮件的收件人地址不是from@from.com ,而是myemailaddress@hotmail.com 。 When I hit reply to the email address then because I have this line:
当我点击回复电子邮件地址时,因为我有这一行:
mail.ReplyToList.Add(new MailAddress("from@from.com"));
The reply to email address does get set to from@from.com . 电子邮件地址的回复确实设置为from@from.com 。
What I want is: 我想要的是:
Right now, it seems to anyone receiving the email that the email has come from myemailaddress@hotmail.com . 现在,在收到电子邮件的任何人看来,该电子邮件已经来自myemailaddress@hotmail.com 。 I thought that the configuration in the web.config that I added was only for authenticating against the smtp.live.com mail server and that the email address wouldn't be used in the email being sent.
我以为我添加的web.config中的配置仅用于针对smtp.live.com邮件服务器进行身份验证,并且该电子邮件地址不会在发送的电子邮件中使用。
What am I doing wrong? 我究竟做错了什么?
Here is a guide you can use to set up your own SMTP server. 这是您可以用来设置自己的SMTP服务器的指南。 Assuming you own "from.com" this will resolve your issue.
假设您拥有“ from.com”,这将解决您的问题。
Have a look at the MSDN Documentation 看看MSDN文档
If you need to send email from many different domains you can configure virtual SMTP servers for each domain. 如果您需要从许多不同的域发送电子邮件,则可以为每个域配置虚拟SMTP服务器。 Have a look at this article .
看一下这篇文章 。
If you do not own the domains that you are attempting to send mail from then it will look like you are spoofing the sender address. 如果您不拥有尝试发送邮件的域,那么您似乎在欺骗发送者地址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.