PowerTCP Mail for .NET
Reply Method
Example 




Address to use for From.
Text for the first part of the new message (Part[0]).
Creates a reply message by inserting a new Textpart. Leaves the original parts unmodified.
Syntax
Public Function Reply( _
   ByVal from As String, _
   ByVal text As String _
) As MailMessage
Dim instance As MailMessage
Dim from As String
Dim text As String
Dim value As MailMessage
 
value = instance.Reply(from, text)
public MailMessage Reply( 
   string from,
   string text
)
public: MailMessage* Reply( 
   string* from,
   string* text
) 
public:
MailMessage^ Reply( 
   String^ from,
   String^ text
) 

Parameters

from
Address to use for From.
text
Text for the first part of the new message (Part[0]).

Return Value

A MailMessage.
Exceptions
ExceptionDescription
System.FormatExceptionIndicates a from or to address is not properly formatted.
Remarks

Useful for situations (such as automation) where the original parts should be left unmodified. For a more UI-centric reply method, use ReplyInline.

The MailMessage is cloned and the 'text' parameter used to initialize a new Textpart which is inserted as Part[0]. The new message is addressed to the "Reply-To" or "From:" header field found in the original message ("Reply-To" supersedes "From:). "Re: " is prepended to the Subject.

This method does not modify the original message. Use ReplyAll to reply to all recipients. Use Forward to forward a message.

The returned message can be modified to change any default values.

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