public static void Run() { // ExStart:SignEmailsWithDKIM string privateKeyFile = Path.Combine(RunExamples.GetDataDir_SMTP().Replace("_Send", string.Empty), RunExamples.GetDataDir_SMTP() + "key2.pem"); RSACryptoServiceProvider rsa = PemReader.GetPrivateKey(privateKeyFile); DKIMSignatureInfo signInfo = new DKIMSignatureInfo("test", "yandex.ru"); signInfo.Headers.Add("From"); signInfo.Headers.Add("Subject"); MailMessage mailMessage = new MailMessage("*****@*****.**", "*****@*****.**"); mailMessage.Subject = "Signed DKIM message text body"; mailMessage.Body = "This is a text body signed DKIM message"; MailMessage signedMsg = mailMessage.DKIMSign(rsa, signInfo); try { SmtpClient client = new SmtpClient("smtp.gmail.com", 587, "*****@*****.**", "your.password"); client.Send(signedMsg); } finally {} // ExEnd:SignEmailsWithDKIM }
public static void Run() { // ExStart:CreateNewMessagesToThunderbird // The path to the File directory. string dataDir = RunExamples.GetDataDir_SMTP(); try { // Open the storage file with FileStream FileStream stream = new FileStream(dataDir + "Please add your Thunderbird file name here", FileMode.Open, FileAccess.Read); // Initialize MboxStorageWriter and pass the above stream to it MboxrdStorageWriter writer = new MboxrdStorageWriter(stream, false); // Prepare a new message using the MailMessage class MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**", "added 1 from Aspose.Email", "added from Aspose.Email"); // Add this message to storage writer.WriteMessage(message); // Close all related streams writer.Dispose(); stream.Close(); // ExEnd:CreateNewMessagesToThunderbird } catch (Exception ex) { Console.WriteLine(ex.Message + "\nPlease add Thunderbird file name to the FileStream"); } }
public static void Run() { // ExStart:ReadMessagesFromThunderbird // The path to the File directory. string dataDir = RunExamples.GetDataDir_SMTP(); // Open the storage file with FileStream FileStream stream = new FileStream(dataDir + "Outlook.pst", FileMode.Open, FileAccess.Read); // Create an instance of the MboxrdStorageReader class and pass the stream MboxrdStorageReader reader = new MboxrdStorageReader(stream, false); // Start reading messages MailMessage message = reader.ReadNextMessage(); // Read all messages in a loop while (message != null) { // Manipulate message - show contents Console.WriteLine("Subject: " + message.Subject); // Save this message in EML or MSG format message.Save(message.Subject + ".eml", SaveOptions.DefaultEml); message.Save(message.Subject + ".msg", SaveOptions.DefaultMsgUnicode); // Get the next message message = reader.ReadNextMessage(); } // Close the streams reader.Dispose(); stream.Close(); // ExEnd:ReadMessagesFromThunderbird }
public static void Run() { // ExStart:SignAMessage // The path to the File directory. string dataDir = RunExamples.GetDataDir_SMTP(); string publicCertFile = dataDir + "MartinCertificate.cer"; string privateCertFile = dataDir + "MartinCertificate.pfx"; X509Certificate2 publicCert = new X509Certificate2(publicCertFile); X509Certificate2 privateCert = new X509Certificate2(privateCertFile, "password"); MailMessage msg = new MailMessage("*****@*****.**", "*****@*****.**", "Signed message only", "Test Body of signed message"); MailMessage signed = msg.AttachSignature(privateCert); MailMessage encrypted = signed.Encrypt(publicCert); MailMessage decrypted = encrypted.Decrypt(privateCert); MailMessage unsigned = decrypted.RemoveSignature();//The original message with proper body MapiMessage mapi = MapiMessage.FromMailMessage(unsigned); // ExEnd:SignAMessage }