我在我的WinForm應用程序編碼在C#中有一些奇怪的行爲。c#從窗體窗體發送郵件不觸發
我: private void buttonSave_Click(object sender, EventArgs e)
林打電話給我的功能: functions.sendStatusEmail();
奇怪的是,當我按下保存按鈕,然後郵件發送不會被觸發。但是,如果我關閉我的應用程序,郵件將被處理併發送。
我是否遺漏了一些東西,或者需要手動觸發som應用程序事件來運行sendout。
(我嘗試使用client.SendAsync(mail,null);
那麼triggerd在點擊,但郵件是空的)
在此先感謝
- 編輯:代碼expamples
private void buttonSave_Click(object sender, EventArgs e)
{
// checks if a ticket is active
if (workingTicketId > 0)
{
// update ticket information
functions.updateTicketInfo(workingTicketId, comboBoxPriority.SelectedIndex,
comboBoxStatus.SelectedIndex, textBoxComment.Text);
// gives feedback
labelFeedback.Text = "Updated";
// updates the active ticket list
populateActiveTicketList();
// marks working ticket row in list
dataGridActiveTicketList.Rows[workingGridIndex].Selected = true;
// checks for change of ticket status
if (comboBoxStatus.SelectedIndex != workingTicketStatus)
{
// checks if contact person exists
if (labelContactPersonValue.Text.ToString() != "")
{
// sends email to contact person
functions.sendStatusEmail(labelContactPersonValue.Text, comboBoxStatus.SelectedIndex, workingTicketId, textBoxDescription.Text);
}
// updates working ticket status
workingTicketStatus = comboBoxStatus.SelectedIndex;
}
}
}
和發送電子郵件功能:
// sends a status email to contact person
// returns noting
public void sendStatusEmail(string email, int newStatus, int ticketId, string ticketText)
{
// defines variables
string emailSubject;
string emailBody;
// some exkluded mailcontent handling
// sends mail
MailMessage mail = new MailMessage("[email protected]n.com",email,emailSubject,emailBody);
SmtpClient client = new SmtpClient(ConfigurationManager.AppSettings["MailSMTP"]);
mail.IsBodyHtml = true;
client.Send(mail);
// dispose
mail.Dispose();
}
郵政sendStatusEmail() – Hemant 2009-06-24 08:35:04
的代碼......並且也採取了buttonSave_Click – 2009-06-24 08:38:55