2016-04-27 98 views
0

一個問題關於MVC發送郵件3.發送郵件MVC 3

當我點擊btnApply應發送2封電子郵件給[email protected]併發送確認到(誰填補電子郵件ID的應用形式是一樣[email protected]

例如:

EMAIL3點擊申請從EMAIL1(發件人)發送郵件電子郵件2(接收器) & Email3(接收器)

EMAIL3點擊申請從電子郵件2(發件人)發送郵件

電子郵件2(接收器) & EMAIL3(接收器)

  1. 我有形式彈出:

    @using (Html.BeginForm()){ 
    Your Full Name 
        <input type="text" value="" id="txtname" name="txtname" required /> 
        Your Email   
        <input type="email" value="" id="txtemail" name="txtemail" required />  
        Upload Your Resume 
        <input name="Upload Saved Replay" id="btnFile" type="file" /> 
        <input type="button" id="btnApply" name="btnApply" value="Apply" /> 
    } 
    
  2. 我有ae郵件管理,它只發送1個郵件從[email protected]電子郵件所指定的申請表格([email protected]

    public class EmailManager 
    { 
        private const string EmailFrom = "[email protected]"; 
        public static void Enquiry(int JobId, string UserName, string Email, string Massage) 
        { 
         using (var client = new SmtpClient()) { 
          using (var message = new MailMessage(EmailFrom, Email)) { 
           message.Subject = "Successful"; 
           message.Body = "<html><head><meta content=\"text/html; charset=utf-8\" /></head><body><p>Dear " + UserName + 
            ", </p> <p>Thankyou for Registering</p>" 
            + "</a></p><div>Best regards,</div><div>Nisha</div></body></html>"; 
           message.IsBodyHtml = true; 
           client.EnableSsl = true; 
           client.Send(message); 
          }; 
         }; 
        } 
    } 
    
+0

'EmailFrom'是'某某@ gmail.com'那麼爲什麼你想將它發送到同一個'XYZ @ gmail的.com' – jamiedanq

+0

我認爲你應該清楚你想做什麼。哪些是EmailFrom,哪些是你發送給Email的。如果您澄清知道如何發送電子郵件更容易。此外,如果你想其他'電子郵件'複製到**電子郵件**您發送明確指示它 – jamiedanq

+0

重命名您的變量'EmailFrom'到'EmailTo'以便於理解和最佳實踐,我建議您評論您的代碼,使其更容易閱讀 – jamiedanq

回答

0

你可以在兩個usings之間使用for循環ID 。

string[] Emails={Email,"[email protected]", "[email protected]"} 
for(var i = 0; i < 3; i++){ 
    using (var message = new MailMessage(EmailFrom, Emails[i])) 
    { 
     message.Subject = "Successful"; 
     message.Body = "<html><head><meta content=\"text/html; charset=utf-8\" /></head><body><p>Dear " + UserName + 
     ", </p> <p>Thankyou for Registering</p>" 
     + "</a></p><div>Best regards,</div><div>Nisha</div></body></html>"; 
     message.IsBodyHtml = true; 
     client.EnableSsl = true; 
     client.Send(message); 
    }; 
} 

可變電子郵件來自虛空Enquiery,其他人都很難在你的代碼編碼

+0

謝謝,但這是可能的硬編碼Email2:[email protected] ?? – Rakyir

+0

這會發送同樣的電子郵件給同一個人3次 – jamiedanq

+0

告訴我,如果這一個作品 –