Hello. I'm having some wierd behaviour in my WinForm application coded in c#.
in my: private void buttonSave_Click(object sender, EventArgs e)
Im calling my function: functions.sendStatusEmail();
The weird thing is that, when i press the Save button then email send is not triggered. But if I close my application the mail is handle and sent.
Have I missed something or do one need to trigger som application event manually to have run the sendout.
( I tried using client.SendAsync(mail,null); then it triggerd at click but the mail was empty)
Thanks in advance
-- Edit: code 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;
}
}
}
and the send email function:
// 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]",email,emailSubject,emailBody);
SmtpClient client = new SmtpClient(ConfigurationManager.AppSettings["MailSMTP"]);
mail.IsBodyHtml = true;
client.Send(mail);
// dispose
mail.Dispose();
}