Я пытаюсь настроить параметры почты на веб-сайте .Net, но smtp в моем web.config игнорируется в пользу настроек smtp, которые, похоже, установлены в файле dll в папке bin.Как применить настройки почты в файле web.config и почему параметры smtp файла dll имеют приоритет над параметрами web.config.Программист, который создавал это (много лет назад и сейчас ушел), также включил настройки smtp в файлы .cs контроллера C #, которые я обновил до правильных настроек smtp, но они тоже игнорируются.Настройки smtp в dll используются в пользу.Я новичок на сайтах .Net, кстати.Я также установил соединение с веб-сайтом с IIS и установил правильные настройки SMTP в панели управления, но не радости.Все сгенерированные системой электронные письма, которые я получаю на свой почтовый ящик, поступают не с того почтового сервера.Я ценю вашу помощь.Спасибо
Настройка почты Web.config:
<system.net>
<mailSettings>
<smtp from="mail@mysite.com">
<network host="smtp.sendgrid.net" port="587" userName="user1" password="pass1" />
</smtp>
</mailSettings>
</system.net>
Web Config full:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="true" />
<defaultDocument>
<files>
<clear />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.pl" />
<add value="default.html" />
<add value="Default.cshtml" />
<add value="index.php" />
<add value="index.html" />
<add value="Default.aspx" />
</files>
</defaultDocument>
<httpProtocol>
<customHeaders>
<clear />
</customHeaders>
</httpProtocol>
</system.webServer>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=152368
-->
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=whatever.com;Initial Catalog=whateverdb;User ID=fakeuser;password=fakepass;Connection Timeout=30;Min Pool Size=20; Max Pool Size=200;" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31434BF3856AD364897979E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF38343456AD3647878E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=3GF655651BF3856AD3648787E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3GHGHGH434425856AD387878764E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=GHGHGH66676731BF38567676AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="1200000" />
</authentication>
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear />
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
<customErrors mode="Off" />
<trust level="Full" />
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.net>
<mailSettings>
<smtp from="mail@mysite.com">
<network host="smtp.sendgrid.net" port="587" userName="user1" password="pass1" />
</smtp>
</mailSettings>
</system.net>
</configuration>
<!--ProjectGuid: 80e45822-7574-4225-9e47-31f80GHGHG5567678545ea-->
.cs code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Data.SqlClient;
using System.Security.Cryptography;
using System.IO;
using System.Net.Mail;
using System.Timers;
....
public bool SendEmail(string Semailid, string encrypted, string EmailID, string PersonsName, string EmailSubject, string mycourse, string encryptStudent,string Certificettemplete)
{
try
{
MailMessage Msg = new MailMessage();
// Sender e-mail address.
Msg.From = new MailAddress(EmailID);
// Recipient e-mail address.
Msg.To.Add(Semailid);
Msg.Subject = EmailSubject;
Msg.IsBodyHtml = true;
Msg.Body = Certificettemplete;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.sendgrid.net";
smtp.Port = 25;
smtp.Credentials = new System.Net.NetworkCredential("user", "pass");
smtp.EnableSsl = false;
smtp.Send(Msg);
Msg = null;
return true;
}
catch (Exception ex)
{
throw ex;
//return false;
}
}