How to send an email from my C# codebehind - Getting System.Net.Mail.SmtpFailedRecipientException

前端 未结 3 438
[愿得一人]
[愿得一人] 2021-01-22 02:23

I have a webform where someone can set up an account - I want to send them an email confirmation.

The code I\'m using:

       // Create e-mail message
           


        
3条回答
  •  我在风中等你
    2021-01-22 02:53

    OK - got it working. Below is the working coding; looks like me configuring the NetworkCredential object was the issue. Thanks everyone though for your assistance in helping me reach the solution.

            MailAddress fromAddress =  new MailAddress("OurOrganisationEmail@ourdomain.com","Our Organisation");//"name@yourdomain.com";
            MailAddress toAddress = new MailAddress("webuser@domain.com", "Web User"); //"name@anydomain.com"; 
    
            //Create the MailMessage instance 
            MailMessage myMailMessage = new MailMessage(fromAddress, toAddress);
    
            //Assign the MailMessage's properties 
            myMailMessage.Subject = "Confirmation";
            myMailMessage.Body = "You are now registered test";
            myMailMessage.IsBodyHtml = true;
    
            //Create the SmtpClient object
            SmtpClient smtp = new SmtpClient();
    
            //Send the MailMessage (will use the Web.config settings) 
            smtp.Send(myMailMessage);
    

    web.config

    
      
        
      
        
      
    
    

提交回复
热议问题