I'm sorry but maybe I'm missing something. I used field specification to set the port so it's not 25

msg.Fields[" http://schemas.microsoft.com/cdo/configuration/smtpserverport";] = 465;

I looked at System.Web.Mail.SmtpClient source code and it reads those fields from message to set socket connection so it should work, if it uses port 25 it should give a timeout error, not an immediately socket exception I think. Field specification works in MS.NET even if not using exchange server (The same code works against google in windows environment). Maybe is one of the most items of MS.NET that does not match the aspected behavior but looking at Mono source code it should use those fields, unless there's some problem with TLS. I tried your code on 2.4.2.3 VM and it waits indefinitely, I've to restart apache. Maybe it's because I don't use Mono 2.6 but this version it's pretty new, in FAQ there's no version specified, I thought it could be used also with older versions, it's a problem for me to update.

At 13.10 03/06/2010, you wrote:
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 = "[email protected]";
> msg.To = "[email protected]";
> 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 = "[email protected]";
             var email = "[email protected]";

             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

_______________________________________________
Mono-aspnet-list mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/mono-aspnet-list

--
Il messaggio e' stato analizzato alla ricerca di virus o
contenuti pericolosi da MailScanner, ed e'
risultato non infetto.
_______________________________________________
Mono-aspnet-list mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/mono-aspnet-list

Reply via email to