I have a problem when i try to call this method in app. It works when the app is on my PC (where was write this code) but when i send app to another client(PC) this doesn't work anymore.
I tried with every port(465,587,25,2525) to more PC. I think is something wrong with connection to the smtp server.
Any idea why it doesn't work to another PC?
private void materialFlatButton1_Click(object sender, EventArgs e)
{
if (indexfeedback == 0)
{
var fromAddress = new MailAddress("xxxxxxxx@gmail.com");
var toAddress = new MailAddress("xxxxxxxxxx@gmail.com");
const string fromPassword = "password";
const string subject = "Subject";
const string body = "Body";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
label444.Text = "SEND !!!";
}
indexfeedback++;
}
else
{
label234.Visible = true;
}
}
Thanks for your help ! I tried for 2 hours at my office to searching for a solution but i didn't find anything