Sends an e-mail message with raw content.
[Visual Basic]
Public Sub SendRawMailAsync( _
server As SmtpServer, _
mail() As Byte, _
from As MailAddress, _
recipients As AddressCollection _
) As IAsyncAction
[C#]
public IAsyncAction SendRawMailAsync(
SmtpServer server,
byte[] mail,
MailAddress from,
AddressCollection recipients
);
[C++]
public: IAsyncAction^ SendRawMailAsync(
SmtpServer^ server,
array<unsigned char>^ mail,
MailAddress^ from,
AddressCollection^ recipients
);
[JScript]
public function SendRawMailAsync(
server : SmtpServer,
mail : Byte[],
from : MailAddress,
recipients : AddressCollection
): IAsyncAction;
Parameters
Return Value
Remarks
Example
[Visual Basic, C#] To get the full samples of EASendMail, please refer to Samples section.
[C# - Forward Email - Windows Store Apps - XAML]
using EASendMail;
using System.Threading.Tasks;
using Windows.Storage;
private async Task ForwardEmail()
{
String Result = "";
try
{
// Get eml file from your current application folder
StorageFile f =
await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///assets/test.eml"));
// Get file from file path
// StorageFile f =
// await StorageFile.GetFileFromPathAsync("d:\\my folder\\test.eml");
var buffer = await FileIO.ReadBufferAsync(f);
Windows.Storage.Streams.DataReader reader = Windows.Storage.Streams.DataReader.FromBuffer(buffer);
byte[] data = new byte[buffer.Length];
reader.ReadBytes(data);
reader.Dispose();
// Set sender email address, please change it to yours
MailAddress from = new MailAddress("test@emailarchitect.net");
// Set recipient email address, please change it to yours
AddressCollection recipients = new AddressCollection("support@emailarchitect.net");
// Your SMTP server address
SmtpServer oServer = new SmtpServer("smtp.emailarchitect.net");
// User and password for ESMTP authentication
oServer.User = "test@emailarchitect.net";
oServer.Password = "testpassword";
// If your SMTP server requires TLS connection on 25 port, please add this line
// oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
// If your SMTP server requires SSL connection on 465 port, please add this line
// oServer.Port = 465;
// oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
SmtpClient oSmtp = new SmtpClient();
await oSmtp.SendRawMailAsync(oServer, data, from, recipients);
Result = "Email was forwareded successfully!";
}
catch (Exception ep)
{
Result = String.Format("Failed to send email with the following error: {0}", ep.Message);
}
// Display Result by Diaglog box
Windows.UI.Popups.MessageDialog dlg = new
Windows.UI.Popups.MessageDialog(Result);
await dlg.ShowAsync();
}
[VB - Forward Email - Windows Store Apps - XAML]
Imports EASendMail
Imports Windows.Storage
Private Async Function ForwardEmail() As Task
Dim Result As String = ""
Try
' Get eml file from your current application folder
Dim f As StorageFile =
Await StorageFile.GetFileFromApplicationUriAsync(New Uri("ms-appx:///assets/test.eml"))
' Get file from file path
'Dim f As StorageFile =
' Await StorageFile.GetFileFromPathAsync("d:\my folder\test.eml")
Dim buffer = Await FileIO.ReadBufferAsync(f)
Dim reader = Windows.Storage.Streams.DataReader.FromBuffer(buffer)
Dim data(buffer.Length - 1) As Byte
reader.ReadBytes(Data)
reader.Dispose()
' Set sender email address, please change it to yours
Dim sender As New MailAddress("test@emailarchitect.net")
' Set recipient email address, please change it to yours
Dim recipients As New AddressCollection("support@emailarchitect.net")
' Your SMTP server address
Dim oServer As New SmtpServer("smtp.emailarchitect.net")
' User and password for ESMTP authentication
oServer.User = "test@emailarchitect.net"
oServer.Password = "testpassword"
' If your SMTP server requires TLS connection on 25 port, please add this line
' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto
' If your SMTP server requires SSL connection on 465 port, please add this line
' oServer.Port = 465
' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto
Dim oSmtp As New SmtpClient()
Await oSmtp.SendRawMailAsync(oServer, Data, sender, recipients)
Result = "Email was forwareded successfully!"
Catch ep As Exception
Result = String.Format("Failed to send email with the following error: {0}", ep.Message)
End Try
' Display Result by Diaglog box
Dim dlg As New Windows.UI.Popups.MessageDialog(Result)
Await dlg.ShowAsync()
End Function
[JavaScript - Forward Email - Windows Store Apps - HTML5]
function forwardEmail()
{
var result = "";
var oSmtp = new EASendMail.SmtpClient();
// Get eml file from your current application folder
Windows.Storage.StorageFile.getFileFromApplicationUriAsync(
new Windows.Foundation.Uri("ms-appx:///assets/test.eml"))
.then(function (f) {
return Windows.Storage.FileIO.readBufferAsync(f);
})
.then(function (buffer) {
var reader = Windows.Storage.Streams.DataReader.fromBuffer(buffer);
var data = new Array(buffer.length);
reader.readBytes(data);
reader.close();
// Set sender email address, please change it to yours
var from = new EASendMail.MailAddress("test@emailarchitect.net");
// Set recipient email address, please change it to yours
var recipients = new EASendMail.AddressCollection("support@emailarchitect.net");
// Your SMTP server address
var oServer = new EASendMail.SmtpServer("smtp.emailarchitect.net");
// User and password for ESMTP authentication
// oServer.user = "test@emailarchitect.net";
// oServer.password = "testpassword";
// If your SMTP server requires TLS connection on 25 port, please add this line
// oServer.connectType = EASendMail.SmtpConnectType.connectSSLAuto;
// If your SMTP server requires SSL connection on 465 port, please add this line
// oServer.port = 465;
// oServer.connectType = EASendMail.SmtpConnectType.connectSSLAuto;
return oSmtp.sendRawMailAsync(oServer, data, from, recipients);
})
.done(function (){
result = "Email was sent successfully!";
(new Windows.UI.Popups.MessageDialog(result, "Success")).showAsync();
},
// error handler
function (e)
{
// because javascript exception only gives the stack trace messages, but it is not
// real description of exception, so we give a property lastErrorMessage for javascript.
if (oSmtp.lastErrorMessage != "") {
result = oSmtp.lastErrorMessage;
}
else {
result = e.message;
}
(new Windows.UI.Popups.MessageDialog(result, "Error Information")).showAsync();
});
}