Send email with wpf

后端 未结 3 1657
迷失自我
迷失自我 2021-02-10 14:38

Hi i am trying to send email in a wpf app but i get stuck; i show my xaml code

 
    
3条回答
  •  梦毁少年i
    2021-02-10 15:36

    You can send mail directly using the System.Net.MailMessage class. Look at the following example from the MSDN documentation for this class:

    public static void CreateTimeoutTestMessage(string server)
            {
                string to = "jane@contoso.com";
                string from = "ben@contoso.com";
                string subject = "Using the new SMTP client.";
                string body = @"Using this new feature, you can send an e-mail message from an application very easily.";
                MailMessage message = new MailMessage(from, to, subject, body);
                SmtpClient client = new SmtpClient(server);
                Console.WriteLine("Changing time out from {0} to 100.", client.Timeout);
                client.Timeout = 100;
                // Credentials are necessary if the server requires the client 
                // to authenticate before it will send e-mail on the client's behalf.
                client.Credentials = CredentialCache.DefaultNetworkCredentials;
    
          try {
                  client.Send(message);
                }  
                catch (Exception ex) {
                  Console.WriteLine("Exception caught in CreateTimeoutTestMessage(): {0}", 
                        ex.ToString() );              
              }
            }
    

提交回复
热议问题