发送电子邮件时,我的web.config上有什么东西

时间:2014-11-24 18:58:24

标签: c# asp.net email web-config

这是我的情况。我们是一家制造工厂。当有人向我们的维护部门提交有关机器问题的内容时,他们必须在两个部门之间进行选择。电子邮件有一个通用的收件人列表,但选项发送给其他人。

我有这个问题,我可以在web.config中更改或添加/删除通用电子邮件列表,但在选择部门时,不会在可选部门电子邮件列表中添加或删除人员。我找不到它被覆盖的地方。

这是aspx.cs表单:

namespace ContactForm
{
public partial class ContactForm : System.Web.UI.Page
{
    public ContactForm()
    {
    }




    protected void SubmitBtn_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            System.Configuration.Configuration config 
                = WebConfigurationManager.OpenWebConfiguration(base.Request.ApplicationPath);
            AppSettingsSection appSettings = (AppSettingsSection)config.GetSection    ("appSettings");

            string emailHost = appSettings.Settings["EmailHost"].Value;
            string fromAddress = appSettings.Settings["FromEmailAddr"].Value;
            string toAddress = appSettings.Settings["ToEmailAddr"].Value;

            SmtpClient smtpClient = new SmtpClient(emailHost);

            // Default in IIS will be localhost 
            //smtpClient.Host = "localhost";

            //Default port will be 25
            smtpClient.Port = 25;

            MailMessage message = new MailMessage();
            message.IsBodyHtml = false;
            message.Priority = MailPriority.High;
            message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

            try
            {
                message.Subject = "Maint Request: " + this.subjectBox.Text;
                message.Body = "From: " + nameBox.Text.Trim() + "\n" + "\n";
                message.Body += "Created At: " + txtDate.Text + "\n" + "\n";
                message.Body += "Department: " + listDepartment.SelectedItem.Text  + "\n" + "\n";
                message.Body += "Priority: " + listPriority.SelectedItem.Text  + "\n" + "\n";
                message.Body += "Machine Area: " + txtMachineArea.Text + "\n" + "\n";
                message.Body += "Machine Number: " +txtMachineNumber.Text + "\n" + "\n";
                message.Body += "Problem description: " + txtQuestion1.Text;
                toAddress += "allmaintenance@webpage.com";
                if (listDepartment.SelectedItem.Text == "Option1")
                {
                    toAddress += ", user1@webpage.com, user2@webpage.com";
                    //toAddress += ", test@webpage.com";
                }
                else if (listDepartment.SelectedItem.Text == "Option2")
                {
                    toAddress += ", user3@webpage.com";
        //toAddress += ", test@webpage.com";

这是web.config文件

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
  <files>
    <clear />
            <add value="index.aspx" />
    <add value="index.html" />
    <add value="Default.htm" />
    <add value="Default.asp" />
    <add value="index.htm" />
    <add value="iisstart.htm" />
    <add value="default.aspx" />
  </files>
 </defaultDocument>
 <staticContent>
  <mimeMap fileExtension=".mp4" mimeType="video/mp4" />
  <mimeMap fileExtension=".ogv" mimeType="video/ogg" />
  <mimeMap fileExtension=".ogg" mimeType="application/ogg" />
  <mimeMap fileExtension=".webm" mimeType="video/webm" />
  <mimeMap fileExtension=".oga" mimeType="audio/oga" />
  <mimeMap fileExtension=".f4v" mimeType="video/mp4" />
 </staticContent>
</system.webServer>
<appSettings>
 <add key="MyEmailAddr" value="noreply@webpage.com" />
 <add key="ToEmailAddr" value="Maintenanceusers@webpage.com" />
 <add key="EmailHost" value="mail.webpage.com" />
 <add key="FromEmailAddr" value="noreply@webpage.com" />
</appSettings>
<system.net>
<mailSettings>
  <smtp from="noreply@webpage.com">
    <network host="mail.webpage.com" />
  </smtp>
</mailSettings>
<!--
    <mailSettings>
        <smtp deliveryMethod='SpecifiedPickupDirectory'>
            <specifiedPickupDirectory pickupDirectoryLocation="c:\maildrop" />
        </smtp>
    </mailSettings>-->
</system.net>
<connectionStrings />
<system.web>
<!-- 
        Set compilation debug="true" to insert debugging 
        symbols into the compiled page. Because this 
        affects performance, set this value to true only 
        during development.
    -->
<compilation debug="true" />
<!--
        The <authentication> section enables configuration 
        of the security authentication mode used by 
        ASP.NET to identify an incoming user. 
    -->
<authentication mode="Windows" />
<!--
        The <customErrors> section enables configuration 
        of what to do if/when an unhandled error occurs 
        during the execution of a request. Specifically, 
        it enables developers to configure html error pages 
        to be displayed in place of a error stack trace.        -->
  <customErrors mode="Off" />
 </system.web>
</configuration>

如果你们能在这里找到任何可以告诉我发生了什么的事情,那么我所做的任何改变都会让我感到惊讶。我几乎不是程序员,几个月前就接管了IT,似乎整件事都是用C#编写的,需要在列表中添加一些电子邮件

1 个答案:

答案 0 :(得分:0)

我通过在Web主机服务器上找到网页并卸载页面并使用更改重新部署它来解决了这个问题