PowerTCP Mail for .NET
Send(Stream) Method
See Also  Example Send comments on this topic.
Dart.PowerTCP.Mail Namespace > Smtp Class > Send Method : Send(Stream) Method




message
A MessageStream object representing an email message.
Synchronously send a MessageStream object that represents an email message.

Syntax

Visual Basic (Declaration) 
Public Overloads Function Send( _
   ByVal message As Stream _
) As SmtpResult
Visual Basic (Usage)Copy Code
Dim instance As Smtp
Dim message As Stream
Dim value As SmtpResult
 
value = instance.Send(message)
C# 
public SmtpResult Send( 
   Stream message
)
Managed Extensions for C++ 
public: SmtpResult* Send( 
   Stream* message
) 
C++/CLI 
public:
SmtpResult^ Send( 
   Stream^ message
) 

Parameters

message
A MessageStream object representing an email message.

Return Value

A SmtpResult object that describes the sent message.

Exceptions

ExceptionDescription
Dart.PowerTCP.Mail.ProtocolExceptionBad SMTP protocol response received from server.
System.Net.Sockets.SocketExceptionThe requested address is not valid in its context.
System.IO.IOExceptionThe filename, directory name, or volume label syntax is incorrect.
System.ArgumentExceptionA required argument contains invalid characters, is empty, or contains only white spaces.

Example

The following example demonstrates creating a basic MIME message with a single attachment.
Visual BasicCopy Code
' Be sure to import the namespace by putting "Imports Dart.PowerTCP.Mail"
' at the top of your class.

' Create a MessageStream object
Dim msg As New MessageStream()

' Add a normal recipient
msg.To.Add(New MailAddress("you@test.com"))

' Add a CC recipient
msg.CC.Add(New MailAddress("you2@test.com"))

' Add a BCC recipient
msg.BCC.Add(New MailAddress("you3@test.com"))

' Specify the sender
msg.From = New MailAddress("me@test.com")

' Specify the subject
msg.Subject = "Hello"

' Add some text to the message.
msg.Text = "Hi everyone. How are ya doing?"

' Add an attachment
msg.Attachments.Add("C:\files\graph.jpg")

' Specify the server
Smtp1.Server = "mail.test.com"

' Send the message
Smtp1.Send(msg)
C#Copy Code
// Be sure to import the namespace by putting "using Dart.PowerTCP.Mail;"
// at the top of your class.

// Create a MessageStream object
MessageStream msg = new MessageStream();

// Add a normal recipient
msg.To.Add(new MailAddress("you@test.com"));

// Add a CC recipient
msg.CC.Add(new MailAddress("you2@test.com"));

// Add a BCC recipient
msg.BCC.Add(new MailAddress("you3@test.com"));

// Specify the sender
msg.From = new MailAddress("me@test.com");

// Specify the subject
msg.Subject = "Hello";

// Add some text to the message.
msg.Text = "Hi everyone. How are ya doing?";

// Add an attachment
msg.Attachments.Add("C:\\files\\graph.jpg");

// Specify the server
smtp1.Server = "mail.test.com";

// Send the message
smtp1.Send(msg);

Remarks

This method should be used to send most email messages. Standard use would involve creating a MessageStream object by doing the following:

  • Creating and initializing a MessageStream object.
  • Setting the sender, receiver, and subject by using the MessageStream.To, MessageStream.From, and MessageStream.Subject properties.
  • Adding Part objects representing MIME parts to the MessageStream.
  • Adding custom header lines (optinal).
  • Sending the message.

To send a message asynchronously, use Smtp.BeginSend.

Use this method to send most messages. The only exception to this is sending simple text message, for which Smtp.Send(String,String,String,String) can be used.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.