0
我正在做我的功課,我點擊一個按鈕「驗證我」後,必須發送電子郵件驗證。不能發送電子郵件(smtp)
下面是按鈕和文本框:
因此,流程是,你必須輸入你的studentID
,然後系統會檢查該數據庫是你的ID存在與否。如果你的studentID存在,我們會發送確認信息(隨機密碼訪問網絡)。
但是在這裏,我很難發送電子郵件,說實話,我不知道什麼是錯的。
這裏是我的部分代碼(僅發送郵件代碼):
public void sendingverification()
{
//get EMAIL from spesific ID
string getEmail = "SELECT Email FROM TableStudent where StudentID = '" + IdTxt.Text + "'";
SqlCommand sqlcomEmail = new SqlCommand(getEmail, con);
//get STUDENT FIRST NAME from spesific ID
string getName = "SELECT StudentFName FROM TableStudent where StudentID = '" + IdTxt.Text + "'";
SqlCommand sqlcomName = new SqlCommand(getName, con);
string randomPw = System.Web.Security.Membership.GeneratePassword(10, 5);
string activationUrl = "http://aws.prominensa.com/izari/web-alumni/login.html";
var fromAddress = new MailAddress("[email protected]", "S2 Alumnae Team");
var toAddress = new MailAddress(sqlcomEmail.ToString(), sqlcomName.ToString());
const string fromPassword = "123456";
const string subject = "Activation Link for S2 Alumnae";
string body = "Hello " + sqlcomName.ToString() + ", ";
body += "<br /><br />your account is almost done. You can login with your account now with this link below.";
body += "<br /><" + activationUrl;
body += "<br />< Please note that you will be able to login using: ";
body += "<br />< StudentID = " + IdTxt.Text;
body += "<br />< Password = " + randomPw;
body += "<br />< Thank you.";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword),
Timeout = 20000
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
}
請問1)編輯你的代碼並寫出正確的C#代碼? 2)你的'''message'''對象似乎在你調用* Send *之前就被處理了,3)你得到了什麼錯誤? – Ruskin
你遇到的異常或錯誤是什麼? –