C# 电子邮件的主题行

C# 电子邮件的主题行,c#,asp.net-mvc,email,C#,Asp.net Mvc,Email,我正在编写一个asp.NETMVC应用程序。在c#中,我想知道是否有人能帮助我理解,是否有可能将数据库中存储的另一个字段的输入,例如数字或文本字符串包含到电子邮件的主题行中 例如,除了主题文本(如“您的活动注册”)之外,我还想在电子邮件的主题行中添加一个“注册ID” 现在我的emailhepler.cs中有一个代码: public static void NotifyHtml(string toAddress, string subject, string body) {

我正在编写一个asp.NETMVC应用程序。在c#中,我想知道是否有人能帮助我理解,是否有可能将数据库中存储的另一个字段的输入,例如数字或文本字符串包含到电子邮件的主题行中

例如,除了主题文本(如“您的活动注册”)之外,我还想在电子邮件的主题行中添加一个“注册ID”

现在我的emailhepler.cs中有一个代码:

public static void NotifyHtml(string toAddress, string subject, string body)
    {
        MailMessage message = new MailMessage();

        message.To.Add(toAddress);
        message.From = new MailAddress("coe-RoomReservations@coe.berkeley.edu");
        message.Subject = subject;

对。希望我没有误解你的问题
MailMessage.Subject
只是String类型的属性,因此可以包含任何格式化为字符串的内容

message.Subject = string.Format("Your event registration; registration id : {0}", registrationId); 

对。当你调用你的方法时,你应该能够按照你想要的方式格式化你的主题。例如:

NotifyHtml("coe-RoomReservations@coe.berkeley.edu", string.format("#{0} Your event registration", registrationId), body);
message.Subject = String.Format("{0} : {1}", subject, registrationID);