PowerTCP Mail for .NET
Forward Method
Example 




Address used for From.
Address used for To.
Text to prepend to the message, added as specified by the format argument.
The desired ForwardFormat.
Creates a forwarded Message.
Syntax
Public Function Forward( _
   ByVal from As String, _
   ByVal to As String, _
   ByVal comment As String, _
   ByVal format As ForwardFormat _
) As MailMessage
Dim instance As MailMessage
Dim from As String
Dim to As String
Dim comment As String
Dim format As ForwardFormat
Dim value As MailMessage
 
value = instance.Forward(from, to, comment, format)
public MailMessage Forward( 
   string from,
   string to,
   string comment,
   ForwardFormat format
)
public: MailMessage* Forward( 
   string* from,
   string* to,
   string* comment,
   ForwardFormat format
) 
public:
MailMessage^ Forward( 
   String^ from,
   String^ to,
   String^ comment,
   ForwardFormat format
) 

Parameters

from
Address used for From.
to
Address used for To.
comment
Text to prepend to the message, added as specified by the format argument.
format
The desired ForwardFormat.

Return Value

A MailMessage
Remarks

The Subject is prepended with "Fwd: ". The original message is not modified.

The returned MailMessage may contain cloned parts, depending on the value of format.

Example
In this example, the Pop component gets only messages with specific subject lines. It then creates and queues "reply" and "forward" response messages for these messages.
//Queued response messages ready for sending
List<MailMessage> queuedMessages = new List<MailMessage>();

private void autoReply(object sender)
{
    //Configure server and account info
    pop1.Session.RemoteEndPoint = new Dart.Mail.IPEndPoint(myServer, Pop.GetDefaultPort(pop1.Session));
    pop1.Session.Username = myUsername;
    pop1.Session.Password = myPassword;

    //Connect and log into the account
    pop1.Connect();
    pop1.Authenticate(true, true);

    //Get header for each message in the account and create response according to subject
    foreach (PopMessage popMessage in pop1.Messages)
    {
        popMessage.Get(0);
        string code = popMessage.Message.Subject;

        //If message contains a specific subject, get entire message then queue an automated response message
        switch (code)
        {
            case "ALERT":
                popMessage.Get();
                //Create a reply message and add it to a list of messages to be sent
                MailMessage replyMessage = popMessage.Message.Reply(fromAddress, "Message acknowledged.");
                queuedMessages.Add(replyMessage);
                break;
            case "ALERT ACK ALL":
                popMessage.Get();
                //Create a reply-all message and add it to a list of messages to be sent
                MailMessage replyAllMessage = popMessage.Message.ReplyAll(fromAddress, "Message acknowledged to all.");
                queuedMessages.Add(replyAllMessage);
                break;
            case "ALERT ELEVATE":
                popMessage.Get();
                //Create a forward message and add it to a list of messages to be sent
                MailMessage forwardMessage = popMessage.Message.Forward(fromAddress, supervisorAddress, "Elevated. Please see message below.", ForwardFormat.Standard);
                queuedMessages.Add(forwardMessage);
                break;
            case "ALERT INFORM":
                popMessage.Get();
                //Create a redirect message and add it to a list of messages to be sent
                MailMessage redirectMessage = popMessage.Message.Forward(fromAddress, colleagueAddress, "Redirected. Please see included message.", ForwardFormat.Redirect);
                queuedMessages.Add(redirectMessage);
                break;
            default:
                break;
        }
    }

    //Gracefully logout
    pop1.Close();

    //Send queued responses (not implemented in this snippet)
    sendResponses();
}

private void sendResponses()
{
    //Configure server and account info
    smtp1.Session.RemoteEndPoint = new IPEndPoint(myServer, Smtp.GetDefaultPort(smtp1.Session));
    smtp1.Session.Username = myUsername;
    smtp1.Session.Password = myPassword;

    //Send all messages in the responses list
    foreach (MailMessage message in queuedMessages)
        smtp1.Send(message);
    queuedMessages.Clear();

    //Gracefully logout
    smtp1.Close();
}
'Queued response messages ready for sending
Private queuedMessages As New List(Of MailMessage)()

Private Sub autoReply(ByVal sender As Object)
    'Configure server and account info
    pop1.Session.RemoteEndPoint = New Dart.Mail.IPEndPoint(myServer, Pop.GetDefaultPort(pop1.Session))
    pop1.Session.Username = myUsername
    pop1.Session.Password = myPassword

    'Connect and log into the account
    pop1.Connect()
    pop1.Authenticate(True, True)

    'Get header for each message in the account and create response according to subject
    For Each popMessage As PopMessage In pop1.Messages
        popMessage.Get(0)
        Dim code As String = popMessage.Message.Subject

        'If message contains a specific subject, get entire message then queue an automated response message
        Select Case code
            Case "ALERT"
                popMessage.Get()
                'Create a reply message and add it to a list of messages to be sent
                Dim replyMessage As MailMessage = popMessage.Message.Reply(fromAddress, "Message acknowledged.")
                queuedMessages.Add(replyMessage)
            Case "ALERT ACK ALL"
                popMessage.Get()
                'Create a reply-all message and add it to a list of messages to be sent
                Dim replyAllMessage As MailMessage = popMessage.Message.ReplyAll(fromAddress, "Message acknowledged to all.")
                queuedMessages.Add(replyAllMessage)
            Case "ALERT ELEVATE"
                popMessage.Get()
                'Create a forward message and add it to a list of messages to be sent
                Dim forwardMessage As MailMessage = popMessage.Message.Forward(fromAddress, supervisorAddress, "Elevated. Please see message below.", ForwardFormat.Standard)
                queuedMessages.Add(forwardMessage)
            Case "ALERT INFORM"
                popMessage.Get()
                'Create a redirect message and add it to a list of messages to be sent
                Dim redirectMessage As MailMessage = popMessage.Message.Forward(fromAddress, colleagueAddress, "Redirected. Please see included message.", ForwardFormat.Redirect)
                queuedMessages.Add(redirectMessage)
            Case Else
        End Select
    Next popMessage

    'Gracefully logout
    pop1.Close()

    'Send queued responses (not implemented in this snippet)
    sendResponses()
End Sub

Private Sub sendResponses()
    'Configure server and account info
    smtp1.Session.RemoteEndPoint = New IPEndPoint(myServer, Smtp.GetDefaultPort(smtp1.Session))
    smtp1.Session.Username = myUsername
    smtp1.Session.Password = myPassword

    'Send all messages in the responses list
    For Each message As MailMessage In queuedMessages
        smtp1.Send(message)
    Next message
    queuedMessages.Clear()

    'Gracefully logout
    smtp1.Close()
End Sub
See Also

Reference

MailMessage Class
MailMessage Members


PowerTCP Mail for .NET Documentation Version 4.3
© 2018 Dart Communications. All Rights Reserved.
Send comments on this topic