简体   繁体   English

发送电子邮件到未设置的地址

[英]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: 我想要的是:

  1. The reply to email address to be from@from.com (as it is now) 回复电子邮件地址为from@from.com (现在)
  2. The to email address to be from@from.com as well. 电子邮件地址也应为from@from.com

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.

相关问题 将类型设置为电子邮件地址 - Set type to Email Address 使用公司 email 地址发送自动化 email - Sending automated email using company email address ExchangeService与AutodiscoverUrl从错误的电子邮件地址发送 - ExchangeService with AutodiscoverUrl sending from wrong email address 发送匿名 email 到我自己的地址 - Sending an anonymous email to my own address 当用户名不是电子邮件地址时,两因素身份验证不将代码发送到电子邮件 - Two factor authentication not sending code to email when UserName is not an email address 在传出 email EWS 中设置回复地址 - set reply-to address in outgoing email EWS 使用 gmail SMTP 从辅助地址发送电子邮件 - Sending email from secondary address using gmail SMTP 使用 NetCore.MailKit 发送电子邮件时地址的 ArgumentNullException - ArgumentNullException for address when sending email using NetCore.MailKit 将带有附件的信息最具体地与谷歌发送到电子邮件地址 - sending information with attachment to an email address most specifacally with google 使用C#中的Outlook对象发送电子邮件时更改发件人的电子邮件地址和名称 - Changing the Sender's email address and name when sending an email using an Outlook object in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM