The code works on a local machine, but one the target machine I get:
"Unable to connect to the remote server"
and
"An attempt was made to access a socket in a way forbidden by its access
permissions xxx.xxx.xxx.xxx:587"
Could permission be denied for doing this on this machine? I can get out to gmail via a web browser.
Code is like this (from SO):
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("your mail@gmail.com");
mail.To.Add("to_mail@gmail.com");
mail.Subject = "Test Mail - 1";
mail.Body = "mail with attachment";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("c:/textfile.txt");
mail.Attachments.Add(attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("your mail@gmail.com", "your password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
It works on one machine, but not another, so I'm assuming some network permission restriction.