Hi,
I'm really struggling to get this one right. I want my button to SAVE the data entered on a webform into the database AND that same button should send a notification mail as well.
This is the basic example of what I've got:
private void button()
{
Save();
SendEmail();
}
private void SendEmail()
{
}
private void Save()
{
}
Okay, now the first part works perfectly fine, and that's the SAVE method(). The SendEMail part is where the struggling starts.
First off. A name in a drop down list is selected (this name corresponds with that person's email address). then the rest is filled in.
Example of a database:
ID Name Email
0 aaa aaa@a.com
So once the dropdownlist is selected, is should select the email address. This part works fine for me too.
Now, when I press on the submit button which Saves data and sends the notification to the person selected, it gives me an SMTP Exception. This is my SendEmail() code:
MailMessage message = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
string msg = string.Empty;
try
{
MailAddress fromAddress = new MailAddress(from);
message.From = fromAddress;
message.Subject = subject;
message.IsBodyHtml = true;
message.Body = body;
smtpClient.Host = "mail.server.com";
smtpClient.Port = 25;
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials = new System.Net.NetworkCredential("info@server.com", "password");
smtpClient.Send(message);
msg = "Successful";
I am pretty sure some setting or something is still not right because I've tried multiple lines of different code to make sure the emails are working, but still get that exception. Sometimes it gives a Time Out Exception.
Yeah, so can anybody help me please.