繁体   English   中英

如何将 email 动态发送给正在使用 C# 中的应用程序的用户?

[英]How to send the email dynamically to the user who is using the application in C#?

这是我的代码,它在提交进程时发送 email 但 email 地址现在是硬编码的。 我想将 email 发送给已登录并使用该应用程序的用户和管理员。 如何将硬编码的 email 地址更改为动态地址

public void SendFinalStatusMail(Guid fileGuid)
{
    PulseTest("Acknowledgement|SendFinalStatusMail| Prepare Mail Content started");

    List<string> toEmailAddresses = new List<string>() { "abc@gmail.com", "bdc@gmail.com", "def@gmail.com" }; //dynamic list for recipients

    string toCCEAddress = String.Empty;
    string toBCCEAddress = String.Empty;
    string subject = "Acknowledgement Mail - " + ProcessCode;
    
    string statusString = String.Empty;

    if (FailedStep == String.Empty) //No Failed Step before acknowledgment;
    {
        statusString = "The process got executed successfully and no errors/warnings were raised.";
    }
    else
    {
        statusString = "The process failed at the step : " + ProcessInformation.CurrentStepCode;
    }

    string bodyHtml = @"<html>
                                    <body>
                                    <p>Hi,</p>
                                    <p>hello nice to meet you: </p>
                                    
    
                                    <p>Regards,</p>
                                    <p>ABC Team</p>
                                    </body>
                                    </html>
                                    ";
    List<string> attachments = new List<string>();
    
    string LogPath = ConfigurationManager.AppSettings["Log"];
    string file = Path.Combine(LogPath, fileGuid.ToString());
    
    attachments.Add(file);

    PulseTest("Acknowledgement|SendFinalStatusMail| Prepare Mail Content completed");
    
    PulseTest("Acknowledgement|SendFinalStatusMail| Send Mail started");
    
    SendMail(toEmailAddresses, toCCEAddress, toBCCEAddress, subject, bodyHtml, attachments);
    
    PulseTest("Acknowledgement|SendFinalStatusMail| Send Mailcompleted");
}

首先,更改您的方法,使其获得一个IEnumerable字符串,代表电子邮件。 接下来,尝试通过传递几种可能的组合来调用它,并检查它是否正确应用了您的参数。

最后,您需要决定如何定义动态 email 集是什么。 如果您要始终将电子邮件发送给同一个人,则可以将其作为配置设置。 或者,您可以将一些数据存储在数据库中,并使用符合您需要的标准加载电子邮件。

因此,您肯定需要将代码重构为以下内容:

public void SendFinalStatusMail(Guid fileGuid, IEnumerable<String> emails) {
    /*Your code*/
}

然后你需要弄清楚你将如何定义传递给这个方法的内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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