简体   繁体   中英

smtp web.config configuration and usage

I have the following problem:

Using asp.net C# and calling several places in code to send email to the user.

However the from address in different sections of the code is different, and I have only one email address configured in web.config. This causes email sent from non-configured email addresses to go to users' junk box, how do I prevent this.

I have the following in web.config. So if from any place in the code the from address i not hello123@site.com, it will go to users' junk box.

  <smtp deliveryMethod="Network">
    <network
      host="smtp.site.com"
      userName="hello123@site.com"
      password="mypassword"
    />
  </smtp>

Here is c# code:

MailMessage message = new MailMessage();
message.From = new MailAddress("forgotyourpassword@abc");
message.To.Add(new MailAddress(this.txt_Email_Pass.Text));
message.Subject = "Welcome to abc";    
message.Body ="abc";
SmtpClient client = new SmtpClient();
client.Send(message);

Unless your code is not setting the From address properly (please post the code). That has to do with your SMTP provider.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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