0

I use System.Web.Mail class to send mail due to System.Net.Mail not supported implicit SSL. My code is the next:

 System.Web.Mail.MailMessage email = new System.Web.Mail.MailMessage();

 string SEND_USING = "http://schemas.microsoft.com/cdo/configuration/sendusing";
 string SMTP_SERVER = "http://schemas.microsoft.com/cdo/configuration/smtpserver";
 string SMTP_SERVER_PORT ="http://schemas.microsoft.com/cdo/configuration/smtpserverport";
 string SMTP_USE_SSL = "http://schemas.microsoft.com/cdo/configuration/smtpusessl";
 string SMTP_AUTHENTICATE = "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate";
 string SEND_USERNAME = "http://schemas.microsoft.com/cdo/configuration/sendusername";
 string SEND_PASSWORD = "http://schemas.microsoft.com/cdo/configuration/sendpassword";

 email.Fields[SEND_USING] = 2;
 email.Fields[SMTP_SERVER] = Conf_SmtpServer;    //is valid
 email.Fields[SMTP_SERVER_PORT] = Conf_Port;     //465
 email.Fields[SMTP_USE_SSL] = Conf_SmtpSsl;      //true
 email.Fields[SMTP_AUTHENTICATE] = 1;
 email.Fields[SEND_USERNAME] = Conf_EmailAddress;
 email.Fields[SEND_PASSWORD] = Conf_PassWord;


 email.From = Conf_FeladoEmailNev + "<" + Conf_DisplayName + ">";
 email.To = System.Convert.ToString(dr["EMAIL"]);

 email.Subject = System.Convert.ToString(dr["TARGY"]);
 email.BodyFormat = System.Web.Mail.MailFormat.Text;
 email.Body = System.Convert.ToString(dr["TEXT"]);

 System.Web.Mail.SmtpMail.Send(email);

When I run SmtpMail.Send method I got the following exception:

System.Web.HttpException (0x80004005): The transport failed to connect
to the server. ---> System.Reflection.TargetInvocationException:
Exception has been thrown by the target of an invocation. --->
System.Runtime.InteropServices.COMException: The transport failed to
connect to the server.

--- End of inner exception stack trace --- at
System.RuntimeType.InvokeDispMethod(String name, BindingFlags
invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers,
Int32 culture, String[] namedParameters) at
System.RuntimeType.InvokeMember(String name, BindingFlags
bindingFlags, Binder binder, Object target, Object[] providedArgs,
ParameterModifier[] modifiers, CultureInfo culture, String[]
namedParams) at
System.Web.Mail.SmtpMail.LateBoundAccessHelper.CallMethod(Object obj,
String methodName, Object[] args) at
System.Web.Mail.SmtpMail.LateBoundAccessHelper.CallMethod(Object obj,
String methodName, Object[] args) at
System.Web.Mail.SmtpMail.CdoSysHelper.Send(MailMessage message) at
System.Web.Mail.SmtpMail.Send(MailMessage message)

I try to find a solution for this, for example maybe this is a permission issue on firewall/gateway, but the right person already checked it, so it's fine.

rene
  • 37,946
  • 78
  • 99
  • 132
user829081
  • 174
  • 1
  • 17
  • 1
    That right person should be able to check your mail server logs and filewall to see what failed. Also if possible try doing the send without SSL/465 to eliminate other causes. – Jon Egerton Dec 17 '14 at 15:18
  • have you tried googling other working examples on how to do thing on `Stackoverflow` [How to send email smtp ssl port 465](http://stackoverflow.com/questions/1011245/how-can-i-send-emails-through-ssl-smtp-with-the-net-framework) || http://www.advancedintellect.com/download.aspx || [System.Net.Mail with SSL to authenticate against port 465](http://blogs.msdn.com/b/webdav_101/archive/2008/06/02/system-net-mail-with-ssl-to-authenticate-against-port-465.aspx) – MethodMan Dec 17 '14 at 15:20
  • Ok, I will check logs. Dj Kraze I see only one difference in this solution, If I am right: System.Web.Mail.SmtpMail.SmtpServer = "smtp.gmail.com:465"; Is this relevant? I only add smtp server and port in mail.Fields – user829081 Dec 17 '14 at 15:29
  • Now I have new information. The mail server has a 3 Certificate in Chain. Maybe this is the problem ? – user829081 Dec 18 '14 at 15:07
  • Can you send test emails? Just drop a eml file on SMTP folder and test if all settings are fine. – danish Jan 05 '15 at 07:48
  • You can `telnet [your smtpserver] 465`? – rene Jan 10 '15 at 10:30

0 Answers0