public void TestAttachmentSort() { // test MailMessage(string, string) constructor MailMessage msg = new MailMessage("*****@*****.**", "*****@*****.**"); // test MailMessage(EamilAddress, EmailAddress) constructor EmailAddress from = new EmailAddress("*****@*****.**", "Fake Sender"); EmailAddress to = new EmailAddress("*****@*****.**", "Fake Recipient"); Attachment att = new Attachment(@"..\lib\test attachments\test.htm"); msg.AddAttachment(att); Attachment att2 = new Attachment(@"..\lib\test attachments\test.gar"); msg.AddAttachment(att2); Attachment att3 = new Attachment(@"..\lib\test attachments\test.zip"); msg.AddAttachment(att3); Attachment att4 = new Attachment(@"..\lib\test attachments\test.longextension"); msg.AddAttachment(att4); ArrayList attachments = msg.Attachments; attachments.Sort(); Console.WriteLine("\r\n ----- MailMessage.Attachments after sorting -----"); foreach (Attachment attachment in attachments) { Console.WriteLine(attachment.Name); } }
protected void Init() { sender = "*****@*****.**"; recipient = "*****@*****.**"; cc = "*****@*****.**"; senderName = "FromName"; recipientName = "ToName"; ccName = "ccName"; subject = "Mail Message Test\r\n"; body = "Hello from MailMessageTest"; htmlBody = "<HTML><HEAD></HEAD><BODY bgColor=\"#00ffff\"><b>Hello Jane. This is the body of the HTML mail message.</b></BODY></HTML>"; charset = "us-ascii"; senderEmail = new EmailAddress(sender, senderName); recipientEmail = new EmailAddress(recipient, recipientName); ccEmail = new EmailAddress(cc, ccName); msg = new MailMessage(senderEmail, recipientEmail); msg.AddRecipient("*****@*****.**", AddressType.To); msg.AddRecipient("*****@*****.**", AddressType.To); msg.Subject = subject; msg.Body = body; msg.Charset = charset; msg.Priority = MailPriority.High; msg.HtmlBody = htmlBody.ToString(); msg.AddRecipient(ccEmail, AddressType.To); msg.AddRecipient(ccEmail, AddressType.Cc); msg.AddCustomHeader("X-Something", "Value"); msg.AddCustomHeader("X-SomethingElse", "Value"); msg.AddAttachment(@"..\lib\test attachments\test.jpg"); msg.AddAttachment(@"..\lib\test attachments\test.htm"); Attachment att = new Attachment(@"..\lib\test attachments\test.zip"); msg.AddAttachment(att); msg.Notification = true; }