SmtpClient.SendRawMail Method


Sends an e-mail message with raw content.

[VisualĀ Basic]
Public Sub SendRawMail( _
    server As SmtpServer, _
    mail() As Byte, _
    from As MailAddress, _
    recipients As AddressCollection _
)

[C#]
public void SendRawMail(
    SmtpServer server,
    byte[] mail,
    MailAddress from,
    AddressCollection recipients
);

[C++]
public: void SendRawMail(
    SmtpServer* server,
    unsigned char mail __gc[],
    MailAddress* from,
    AddressCollection* recipients
);

[JScript]
public function SendRawMail( 
    server : SmtpServer, 
    mail : Byte[],
    from : MailAddress,
    recipients : AddressCollection
);

Parameters

server
A SmtpServer instances used to send email.
mail
A byte array instance which contains the email content to send.
from
A MailAddress instance represents the email sender.
recipients
A AddressCollection instance represents the email recipients.

Remarks

This method is used to send the customized email content. For example, you can use this method to forward an email without changing anything in the email.

Example

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

[Visual Basic]
Imports EASendMail
Imports System.IO

Sub SendMail()
    Dim oSmtp As SmtpClient = New SmtpClient

    Try
        Dim oServer As SmtpServer = New SmtpServer("myserveraddress")
  
        Dim from As New MailAddress("from@adminsystem.com")
        Dim recipients As New AddressColleciton("to@adminsystem.com")

        Dim fs As New FileStream( "c:\test.eml", FileMode.Open, FileAccess.Read, FileShare.Read)
        Dim mail(fs.Length-1) As Byte
        fs.Read(mail, 0, fs.Length)
        fs.Close()
               
        oSmtp.SendRawMail( oServer, mail, from, recipients )
        Console.WriteLine( "message was sent" )
        
    Catch exp As SmtpTerminatedException
        Console.WriteLine(exp.Message)
    Catch exp As SmtpServerException
        Console.WriteLine("Exception: Server Respond: {0}", exp.ErrorMessage)
    Catch exp As System.Net.Sockets.SocketException
        Console.WriteLine("Exception: Networking Error: {0} {1}", exp.ErrorCode, exp.Message)
    Catch exp As System.ComponentModel.Win32Exception
        Console.WriteLine("Exception: System Error: {0} {1}", exp.ErrorCode, exp.Message)
    Catch exp As System.Exception
        Console.WriteLine("Exception: Common: {0}", exp.Message)
    End Try

    Console.WriteLine("SMTP LOG:" & vbCrLf)
    Console.WriteLine(oSmtp.SmtpConversation)
End Sub

[C#]
using System;
using EASendMail;
using System.IO;

void SendMail()
{
    SmtpClient oSmtp = new SmtpClient();

    try
    {
        SmtpServer oServer = new SmtpServer("myserveraddress");
        MailAddress from = new MailAddress("from@adminsystem.com");
        AddressColleciton recipients = new AddressColleciton("to@adminsystem.com");

        FileStream fs = new FileStream( "c:\\test.eml", FileMode.Open, FileAccess.Read, FileShare.Read);
        byte[] mail = new byte[fs.Length];
        fs.Read(mail, 0, fs.Length);
        fs.Close()
               
        oSmtp.SendRawMail( oServer, mail, from, recipients );
	    Console.WriteLine( "message was sent" );
    }
    catch( SmtpTerminatedException exp )
    {
        Console.WriteLine( exp.Message );
    }
    catch( SmtpServerException exp )
    {
        Console.WriteLine( "Exception: Server Respond: {0}", exp.ErrorMessage );
    }
    catch( System.Net.Sockets.SocketException exp )
    {
        Console.WriteLine( "Exception: Networking Error: {0} {1}", exp.ErrorCode, exp.Message );
    }
    catch( System.ComponentModel.Win32Exception exp )
    {
        Console.WriteLine( "Exception: System Error: {0} {1}", exp.ErrorCode, exp.Message );            
    }
    catch( System.Exception exp )
    {
        Console.WriteLine( "Exception: Common: {0}", exp.Message );         
    }

    Console.WriteLine( "SMTP LOG:\r\n" );
    Console.WriteLine( oSmtp.SmtpConversation );
}