[Mono-aspnet-list] Socket error sending secured mail.
Robert Jordan
robertj at gmx.net
Thu Jun 3 07:10:29 EDT 2010
On 03.06.2010 11:10, APS wrote:
> Hi,
>
> I'm trying so send secured mail with mono using System.Web.Mail in aspnet.
> I read this
> <http://www.mono-project.com/FAQ:_Security#Does_SSL_works_for_SMTP.2C_like_GMail_.3F>http://www.mono-project.com/FAQ:_Security#Does_SSL_works_for_SMTP.2C_like_GMail_.3F
> 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;
>
> msg.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"]
> = "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");
smtp.Send(mail);
}
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
http://www.mono-project.com/FAQ:_Security#Does_SSL_works_for_SMTP.2C_like_GMail_.3F.
Robert
More information about the Mono-aspnet-list
mailing list