SmtpMail.SaveAs Method


Saves the e-mail message to a file (*.eml file).

[Visual Basic]
Public Sub SaveAs( _
    fileName As String, _
    overwrite As Boolean _
)
[C#]
public void SaveAs(
    string fileName,
    bool overwrite
);
[C++]
public: void SaveAs(
    String^ fileName,
    bool overwrite
);
[JScript]
public function SaveAs( 
    fileName : String
    overwrite : Boolean
);

Parameters

fileName
The file name to save.
overwrite
A boolean value indicates whether this method overwrites the file if the file is existed.

Example

[Visual Basic, C#, C++] To get the full samples of EASendMail, please refer to Samples section.

[VB - Edit and Send Email]

Imports EASendMail

Sub SendMail()

    Try
        Dim oMail As SmtpMail = New SmtpMail("TryIt")
        oMail.From = New MailAddress("from@adminsystem.com")
        oMail.To.Add(New MailAddress("to@adminsystem.com"))
        
        oMail.Subject = "test subject"
        oMail.TextBody = "test body"
                
        oMail.SaveAs("c:\test.eml", True)
        oMail.Reset()
        oMail.LoadMessage("c:\test.eml")
                        
        ' change subject
        oMail.Subject = "new email subject"

        Dim oServer As SmtpServer = New SmtpServer("myserveraddress")
        ' SMTP user authentication
        oServer.User = "myusername"
        oServer.Password = "mypassword"

        ' Most mordern SMTP servers require SSL/TLS connection now.
        ' ConnectTryTLS means if server supports SSL/TLS, SSL/TLS will be used automatically.
        oServer.ConnectType = SmtpConnectType.ConnectTryTLS

        Dim oSmtp As SmtpClient = New SmtpClient
        oSmtp.SendMail(oServer, oMail)
        Console.WriteLine("message was sent")
        
    Catch exp As Exception
        Console.WriteLine("Exception: Common: {0}", exp.Message)
    End Try
    
End Sub


[C# - Edit and Send Email] using System; using EASendMail; void SendMail() { try { SmtpMail oMail = new SmtpMail("TryIt"); oMail.From = new MailAddress("from@adminsystem.com"); oMail.To.Add( new MailAddress("to@adminsystem.com")); oMail.Subject = "test subject"; oMail.TextBody = "test body"; // save email oMail.SaveAs("c:\\test.eml", true); oMail.Reset(); oMail.LoadMessage("c:\\test.eml"); // change subject oMail.Subject = "new email subject"; SmtpServer oServer = new SmtpServer("myserveraddress"); // SMTP user authentication oServer.User = "myusername"; oServer.Password = "mypassword"; // Most mordern SMTP servers require SSL/TLS connection now. // ConnectTryTLS means if server supports SSL/TLS, SSL/TLS will be used automatically. oServer.ConnectType = SmtpConnectType.ConnectTryTLS; SmtpClient oSmtp = new SmtpClient(); oSmtp.SendMail(oServer, oMail); Console.WriteLine("message was sent"); } catch(Exception exp) { Console.WriteLine("Exception: {0}", exp.Message); } }
[C++/CLI - Edit and Send Email] using namespace System; using namespace EASendMail; void SendMail() { try { SmtpMail ^oMail = gcnew SmtpMail("TryIt"); oMail->From = gcnew MailAddress("from@adminsystem.com"); oMail->To->Add(gcnew MailAddress("to@adminsystem.com")); oMail->Subject = "test subject"; oMail->TextBody = "test body"; // save copy oMail->SaveAs("c:\\test.eml", true); oMail->Reset(); oMail->LoadMessage("c:\\test.eml"); // change subject oMail->Subject = "new email subject"; SmtpServer ^oServer = gcnew SmtpServer("myserveraddres"); // SMTP user authentication oServer->User = "myusername"; oServer->Password = "mypassword"; // Most mordern SMTP servers require SSL/TLS connection now. // ConnectTryTLS means if server supports SSL/TLS, SSL/TLS will be used automatically. oServer->ConnectType = SmtpConnectType::ConnectTryTLS; SmtpClient ^oSmtp = gcnew SmtpClient(); oSmtp->SendMail(oServer, oMail); Console::WriteLine("message was sent"); } catch(Exception ^exp) { Console::WriteLine("Exception: {0}", exp->Message); } }

See Also

SmtpMail.LoadMessage Method