How to read system.net/mailSettings/smtp from Web.config

后端 未结 7 2214
萌比男神i
萌比男神i 2021-01-31 01:16

This is my web.config mail settings:


    
      

        
7条回答
  •  不要未来只要你来
    2021-01-31 01:57

    I think if you have defaultCredentials="true" set you will have the credentials = null as you are not using them.

    Does the email Send when you call the .Send method?

    So

    This is my web config mail settings:

    
       
          
             
          
       
    
    

    and this is cs

    SmtpClient smtpClient = new SmtpClient();
    
    string smtpDetails =
        @"
        DeliveryMethod = {0},
        Host = {1},
        PickupDirectoryLocation = {2},
        Port = {3},
        TargetName = {4},
        UseDefaultCredentials = {5}";
    
    Console.WriteLine(smtpDetails,
        smtpClient.DeliveryMethod.ToString(),
        smtpClient.Host,
        smtpClient.PickupDirectoryLocation == null
            ? "Not Set"
            : smtpClient.PickupDirectoryLocation.ToString(),
        smtpClient.Port,
        smtpClient.TargetName,
        smtpClient.UseDefaultCredentials.ToString)
    );
    

提交回复
热议问题