[Mono-aspnet-list] Socket error sending secured mail.
robertj at gmx.net
Thu Jun 3 07:10:29 EDT 2010
On 03.06.2010 11:10, APS wrote:
> I'm trying so send secured mail with mono using System.Web.Mail in aspnet.
> I read this
> and I made the described operations but when I try to send the mail I
> always immediately obtain
> System.Web.HttpException: Connection refused --->
This is expected because you're actually connecting on port 25.
> System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
> msg.From = "test at gmail.com";
> msg.To = "test at gmail.com";
> msg.Subject = "test";
> msg.Body = "test";
> msg.BodyFormat = System.Web.Mail.MailFormat.Html;
> = "smtp.gmail.com";
This fields base configuration is of no use unless you're relaying
the mail through a Microsoft Exchange saver.
You're supposed to do something like that (code borrowed
from Abe Gillespie/Mono list):
static void SendEmail()
var sender = "sender at gmail.com";
var email = "receiver at mail.com";
var from = new MailAddress(sender, "Sender");
var to = new MailAddress(email);
var mail = new MailMessage(from, to);
// Set the content.
mail.Subject = "Subject";
mail.Body = "Body";
// Send the message.
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;
smtp.Credentials = new NetworkCredential(sender, "password");
You'll need Mono 2.6.x (or 2.4 + Mono.Security.dll from 2.6,
at you own risk) and don't forget to import the
certs as described here
More information about the Mono-aspnet-list