2 using System
.Collections
.Generic
;
4 using System
.ComponentModel
;
8 using System
.Windows
.Controls
;
9 using System
.Windows
.Media
;
16 public void SendCompletedCallback(object sender
, AsyncCompletedEventArgs e
)
18 // Get the unique identifier for this asynchronous operation.
19 String token
= (string)e
.UserState
;
24 client
.SendAsyncCancel();
25 CreateDialog(e
.Error
.ToString());
31 CreateDialog("Message Sent");
39 private static void CreateDialog(string msg
)
41 Window w
= new Window();
42 StackPanel sp
= new StackPanel();
43 sp
.Background
= Brushes
.Transparent
;
44 TextBlock tb
= new TextBlock();
45 tb
.Background
= sp
.Background
;
46 tb
.TextWrapping
= TextWrapping
.Wrap
;
51 w
.WindowStyle
= WindowStyle
.ToolWindow
;
52 w
.Background
= Window2
.ChangeBackgroundColor(Colors
.Wheat
);
58 public Email(string server
, string login
, int port
, bool sslCheck
, string toAddr
, string fromAddr
, string password
, string bodyMessage
,EmailDialog emailDia
, string subject
)
63 NetworkCredential nw
= new NetworkCredential(login
, password
);
64 // Command line argument must be the SMTP host.
65 client
= new SmtpClient(server
);
66 client
.Credentials
= nw
;
67 client
.EnableSsl
= (sslCheck
== true) ? true : false;
68 // Specify the e-mail sender.
69 // Create a mailing address that includes a UTF8 character
70 // in the display name.
72 MailAddress
from = new MailAddress(fromAddr
, "", System
.Text
.Encoding
.UTF8
);
74 // Set destinations for the e-mail message.
75 MailAddress to
= new MailAddress(toAddr
);
76 // Specify the message content.
77 message
= new MailMessage(from, to
);
78 message
.Body
= bodyMessage
;
80 message
.Subject
= subject
;
81 message
.SubjectEncoding
= System
.Text
.Encoding
.UTF8
;
83 // Set the method that is called back when the send operation ends.
84 client
.SendCompleted
+= new
85 SendCompletedEventHandler(SendCompletedCallback
);
86 // The userState can be any object that allows your callback
87 // method to identify this send operation.
88 // For this example, the userToken is a string constant.
89 string userState
= "Sticky note message";
90 client
.SendAsync(message
, userState
);
94 CreateDialog(e
.Message
);
106 private SmtpClient client
= null;
107 private MailMessage message
= null;
108 private bool mailSent
= false;
109 private EmailDialog dia
= null;