简体   繁体   English

email 消息的主题行

[英]subject line of email message

I'm writing an asp.net mvc app.我正在写一个 asp.net mvc 应用程序。 in c#, and I'm wondering if anybody can help me to understand, if it's possible to include an input from another field stored in the database, like a numeric or text string into a subject line of the email.在 c# 中,我想知道是否有人可以帮助我理解,是否可以将来自存储在数据库中的另一个字段的输入(例如数字或文本字符串)包含到 email 的主题行中。

For example, along with the subject text, like "Your event registration" I'd like to add a "registartion ID" into a subject line of my email.例如,除了主题文本,如“您的活动注册”,我想将“注册 ID”添加到我的 email 的主题行中。

Right now i have a code in my emailhepler.cs:现在我的 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;

Yes.是的。 When you call your method, you should be able to format your subject however you want.当您调用您的方法时,您应该能够根据需要设置主题的格式。 Eg,例如,

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

Yes.是的。 Hope I didn't misunderstand your question.希望我没有误解你的问题。 MailMessage.Subject is just a property of type String so you can include anything that's formatted as a string. MailMessage.Subject只是 String 类型的属性,因此您可以包含任何格式化为字符串的内容。

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

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

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