TIdSMTP->Send() and LastCmdResult [Edit]

Hello!

I would like to add some information and do some cleanup processing if my Send() call fails, so I'm trying to catch the exception and use LastCmdResult.  Here is some slightly simplified code:

{code}
	String errormsg = "";

	__try
	{
		try
		{
			DataModuleShared->IdSMTP1->Send(message);
		}
		catch(...)
		{
			errormsg = DataModuleShared->IdSMTP1->LastCmdResult->FormattedReply->Text;
			if (errormsg.Length() == 0)
				errormsg = "Unable to send email to " + message->Recipients->EMailAddresses;
			Application->MessageBox(errormsg.c_str(), L"Error!", MB_OK);
		}
	}
	__finally
	{
		DataModuleShared->IdSMTP1->Disconnect();
	}
{code}

To test this code, my recipient email address is invalid.  If I remove the exception code, a dialog is shown with the message: "<invalidemail.com>:recipient address must contain a domain".  However, when I catch the exeption and attempt to query for the error, I get "250 Reset OK".

Is there some other mechanism to get the actual error message?

Thanks so much for your help!
-Karen

Edited by: Karen Cate on Dec 7, 2011 1:02 PM
0
Karen
12/7/2011 9:02:48 PM
embarcadero.cppbuilder.socket 566 articles. 0 followers. Follow

1 Replies
1120 Views

Similar Articles

[PageSpeed] 37

Karen wrote:

> I would like to add some information and do some cleanup processing if
> my Send() call fails, so I'm trying to catch the exception and use
> LastCmdResult. 

Depending on which command failed, LastCmdResult may not hold the result 
of the command that actually failed.  It may hold the result of a command 
that was sent after the failing command.  When a command fails, an EIdReplyRFCError 
exception is raised, which contains the actual error data for the failing 
command.  You should be using that instead, eg:

{code:cpp}
try
{
    try
    {
        DataModuleShared->IdSMTP1->Send(message);
    }
    catch(const Exception &e)
    {
        String errormsg;
        const EIdReplyRFCError *err = dynamic_cast<const EIdReplyRFCError*>(&e);
        if (err != NULL)
            errormsg = err->Message;
        if (errormsg.IsEmpty())
            errormsg = "Unable to send email to " + message->Recipients->EMailAddresses;
        Application->MessageBox(errormsg.c_str(), L"Error!", MB_OK);
    }
}
__finally
{
    DataModuleShared->IdSMTP1->Disconnect();
}
{code}

> To test this code, my recipient email address is invalid.  If I remove
> the exception code, a dialog is shown with the message:
> "<invalidemail.com>:recipient address must contain a domain".
> However, when I catch the exeption and attempt to query for the error,
> I get "250 Reset OK".

If Send() encounters a server error during the "RCPT TO" or "DATA" commands, 
it sends a RSET command to the server to discard any message data that was 
already sent.  You are seeing the result of the RSET command in LastCmdResult, 
but the exception was raised from one of the earlier commands.

--
Remy Lebeau (TeamB)
0
Remy
12/7/2011 9:20:54 PM
Reply:

Similar Artilces:

Edit->Preferences->Attachments->View & Edit Actions
Name: Leroy Tennison Email: leroy_tennisonatprodigydotnet Product: Thunderbird Summary: Edit->Preferences->Attachments->View & Edit Actions Comments: Enhancement request: Add a 'New Action' option to the "Download Actions" dialog so that associations can be added without actually having to receive atype of attachment and go through the Browse process of locating the executable. Thanks for all your work. Browser Details: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.12) Gecko/20071020 CentOS/1.5.0.12-0.7.el4.centos Firefox/1.5.0.12 pango-tex...

send file over socket [Edit]
I am trying to send a file over socket via a string, i use a tcpserversocket and a tcpclientsocket. I send the file via text(with TIdEncoderMIME.EncodeStream). But i can't send so many text over a socket so i want to split the text, i now have a script to split the text: {code} S := sendstring; A := TStringList.Create; while S <> '' do begin A.Add(Copy(S, 1, 1050)); Delete(S, 1, 1050); end; for s in a do begin SendTextToSocket(form1.ServerSocket1.Socket.Connections[form1.ListView1.Selected.Index],s); end; {code} But...

PHP -> JSON ->Zlib -> Delphi XE7 [win32 -> work | android -> No mapping ] [Edit]
Мy program for android should get data from the server as yson when to perform under vindovs works, and in android error, please help! PHP: {code} $err = array(); $data = array('id'=>1,'name'=>'test','info'=>'1234'); $inf = array('data' => $data ,'error' => $err); $json = json_encode($inf); $json = gzencode(trim(preg_replace('/\s+/',' ',$json )),9); header('Content-Encoding: gzip'); header("content-type: text/html; charset: UTF-8"); header("cache-control: must-revalidate&qu...

PHP -> JSON ->Zlib -> Delphi XE7 [win32 -> work | android -> No mapping ] [Edit] #2
Мy program for android should get data from the server as yson when to perform under vindovs works, and in android error, please help! PHP: {code} $err = array(); $data = array('id'=>1,'name'=>'test','info'=>'1234'); $inf = array('data' => $data ,'error' => $err); $json = json_encode($inf); $json = gzencode(trim(preg_replace('/\s+/',' ',$json )),9); header('Content-Encoding: gzip'); header("content-type: text/html; charset: UTF-8"); header("cache-control: must-revalidate&qu...

PHP -> JSON ->Zlib -> Delphi XE7 [win32 -> work | android -> No mapping ] [Edit] #2
Мy program for android should get data from the server as json when to perform under Win32 works, and in android error, please help! PHP: {code} $err = array(); $data = array('id'=>1,'name'=>'test','info'=>'1234'); $inf = array('data' => $data ,'error' => $err); $json = json_encode($inf); $json = gzencode(trim(preg_replace('/\s+/',' ',$json )),9); header('Content-Encoding: gzip'); header("content-type: text/html; charset: UTF-8"); header("cache-control: must-revalidate"...

PHP -> JSON ->Zlib -> Delphi XE7 [win32 -> work | android -> No mapping ] [Edit] #2
Мy program for android should get data from the server as yson when to perform under vindovs works, and in android error, please help! PHP: {code} $err = array(); $data = array('id'=>1,'name'=>'test','info'=>'1234'); $inf = array('data' => $data ,'error' => $err); $json = json_encode($inf); $json = gzencode(trim(preg_replace('/\s+/',' ',$json )),9); header('Content-Encoding: gzip'); header("content-type: text/html; charset: UTF-8"); header("cache-control: must-revalidate&qu...

TIdSMTP->Connect hangs [Edit]
I'm trying to figure out why TIdSMTP never returns or throws an exception when calling Connect(). In my original project when I encountered the problem I used SSL. To dumb the problem down, I made a simple project with IdSMTP1 and Button1 on it. IdSMTP1 has server set to smtp.gmail.com, port set to 465, user name set to non-existing-address@gmail.com and password set to 123456. onClick of the button called IdSMTP1->Connect(); I also processed onStatus events that produced Resolving, Connecting and Connected messages. Connected is the last message I received from it. Adding IdSSLIOH...

How to send gmail by Indy (TIdSMTP)? [Edit]
My code to send gmail: {code} procedure SendEmail(const Recipients: string; const Subject: string; const Body: string); var SMTP: TIdSMTP; Email: TIdMessage; SSLHandler: TIdSSLIOHandlerSocketOpenSSL; eFrom: string; begin eFrom := 'duytuanvn@gmail.com'; SMTP := TIdSMTP.Create(nil); Email := TIdMessage.Create(nil); SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil); try SSLHandler.MaxLineAction := maException; SSLHandler.SSLOptions.Method := sslvTLSv1; SSLHandler.SSLOptions.Mode := sslmUnassigned; SSLHandler.SSLOptions.VerifyMode...

ERROR >>>>>>>>>>>master page
can any budy give me an answer of given question this question is ask in interview we have an usercontrol in .net 1.0,1.1 why microsoft implimented the masterpage concept in 2.0 as work done by master page is same as usercontrol do   can any budy gives mw an ans -----------why we use master pages........???????? Friend, this article explains you why do we use the master pages http://dotnetperls.com/Content/Master-Page-Code-Behind.aspx and this one http://www.careerride.com/ASP.NET-Master-Pages-Questions.aspx Good luck!Please Don't forget to click "Mark as Answer&quo...

Editable DataGrid --> DropDown List --> How to retreive SelectedItem when clicking Edit button
<asp:TemplateColumn HeaderText="V.Type" SortExpression="vehicle_type" ItemStyle-Width="50px" ItemStyle-HorizontalAlign="left"> <ItemTemplate> <%#DataBinder.Eval(Container.DataItem , "vehicle_type")%> </ItemTemplate> <EditItemTemplate> <asp:DropDownList id="dd_vehicle_type" runat="server"> <asp:ListItem><%#DataBinder.Eval(Container.DataItem , "vehicle_type")%></asp:ListItem> <asp:ListItem>Sedan</asp:ListI...

DataList -> Edit Template -> DropDownList -> AutoPostBack
Good Afternoon,I have a datalist control that you can use to edit the info...Inside the EditItemTemplate I have a DropDownList that I want to have an AutoPostback coupled with a OnSelectedIndexChanged method.Now this is all fine and dandy but what I can't get to work is that when this method fires I hit the database and then change the value of another dropdownlist inside the EditItemTemplate.Now the part I'm having an issue with is trying to retrive the instance of the dropdownlist I want to change.Follow?Thanks in advance!CharlesPs. If you need more info just ask. Shot. Just an example f...

How to change image width in DataGrid > TemplateColumn > Edit DataBindings > Image > Width
I've a template column in a datagird.In this column I insert an image ,  I want to change image width into data in filed "PercentComplete"(In my data table).This is code<ItemTemplate> <div style="width: 100px; height: 7px"> <asp:Image ID="Image1" runat="server" ImageUrl="~/images/percent_tab.JPG" Width='<%# DataBinder.Eval(Container.DataItem,"Complete") %>' /> </div> </ItemTemplate> And I've and error message when I start website , "Specified cast is not vali...

TIdSMTP->Send Exception without Message
Hi. When I send emails with .... try { IdSMTP1->Send(); } catch (Exception &e) { fprintf (fp, "Could not send mail. Error:'%s'\n", e.Message.c_str()); } .... It happens, that I have entries in my log file with an empty error message (...Error:''). What kinds of error can cause such behaviour, or is there an error in my program? (Using an equivalent program structure to connect to the smtp server logs the reason if a connection is impossible). C.N.Taur Il Tue, 23 Feb 2010 05:03:19 -0800, Registered User <nospam_nghe@nowh...

A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied
Hi Guys Getting this error whe try to connect godaddy mysql database. My connection string is string connectionString = "Server=proxy.shr.secureserver.net;Port=9999; Database=xxxx; Uid=xxxx; Pwd=xxxxxx;Pooling=false;Pooling=false"; How to fix this. Pl. help. Thanks.  A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more informat...

Web resources about - TIdSMTP->Send() and LastCmdResult [Edit] - embarcadero.cppbuilder.socket

Resources last updated: 12/14/2015 8:44:48 AM