I\'m referring to this guide on C# SMTP mail.
Here is my code:
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient(\"smtp.gm
Check if code below would work for you; I've tested it on my gmail account and it seem to work fine with my mono 2.0 running on ubuntu 10.04LTS
using System;
using System.Net;
using System.Net.Mail;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
namespace mono_gmail
{
class MainClass
{
public static void Main (string[] args)
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("my.name@gmail.com");
mail.To.Add("my.name@hotmail.com");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail from GMAIL";
SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential("my.name", "my.password");
smtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
smtpServer.Send(mail);
}
}
}
solution is taken from here
hope this helps, regards
Found another solution from SmtpClient with Gmail
certmgr -ssl smtps://smtp.gmail.com:465
If you are running mono web server, run command with same username as mono process.
The correct solution is not to remove SSL Certificate Validation. GMail has a valid certificate. The problem is that Mono can't seem to find the certificate.
This is completely wrong for so many reasons, but mainly because it removes a very important certificate validation:
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
The correct solution is to install the certificate in your machine:
mozroots --import --ask-remove --machine
certmgr -ssl smtps://smtp.gmail.com:465
This will effectively download the certificate for gmail and it will make it available for mono to use.
You do not have the appropriate certificate authorities installed somewhere where Mono can see them. Please have a look at the Mono project security FAQ for the steps to remedy this error.
Have you tried changing the port, I know the default SMTP port for SSL is 465
If you're using SSL rather than TLS, you need port 465 rather than 587.
See http://mail.google.com/support/bin/answer.py?hl=en&answer=13287.