Error when sending mail via SMTP

tsvtsv Member Posts: 49
Hi,

I have created a function to send mail from sales order and below is my code
cduMail.CreateMessage(USERID,recUserTemp."E-Mail",recUserSetup."E-Mail",txtSubject,txtBody,TRUE);
cduMail.send;
Message('Notification mail have been sent');
I have given a wrong mail id which does not exist in my Exchange server and the system is given an error message as
Your email meesage was unable to sent because your mail server rejected the message: Client does not have permission to send as this sender
This is fine.
but it is also displaying the message as "Notification mail have been sent".
so how to stop the message from displaying.
Any help..

Thanks Inadvance...
with regards,
tsv

Comments

  • Alex_ChowAlex_Chow Member Posts: 5,063
    This is something external to NAV. You have to check to see if your mail server to see why it's not sending.
  • tsvtsv Member Posts: 49
    thanks for the reply...
    I have given an invalid email id to check my code and since the email id is invalid the exchange server has given an error message. this is valid.
    my problem is even if the mail is not sent the message that is given below is displaying.
    cduMail.send;
    Message('Notification mail have been sent');
    

    do i have to put sleep command before the message like below
    cduMail.send;
    sleep(1000);
    Message('Notification mail have been sent');
    
    with regards,
    tsv
  • tsvtsv Member Posts: 49
    any help.. ](*,)
    with regards,
    tsv
  • mkpjsrmkpjsr Member Posts: 587
    tsv wrote:
    any help.. ](*,)

    I think you should put your code like this..

    if Mail Send Succeffully Then
    Message('Mail Sent')
    else
    Message('Error occured')
  • tsvtsv Member Posts: 49
    But there is no return value for Send function in SMTP (ID 400) codeunit.
    with regards,
    tsv
  • MBergerMBerger Member Posts: 413
    What version of NAV are you using ? if i look at the Send() function in CU 400 in a 6.0 SP 1 Cronus DB, i see the following code :
    WITH SMTPMailSetup DO
      Result :=
        Mail.Send(
          "SMTP Server",Authentication <> SMTPMailSetup.Authentication::Anonymous,"User ID", Password);
    CLEAR(Mail);
    IF Result <> '' THEN
      ERROR(Text003,Result);
    
    So IF there is an error that is detectable, it should be fired.

    Maybe you are using an older or customized version ? If not, then you are having an error that is not reported back to NAV, and you are out of luck.
  • vijay_gvijay_g Member Posts: 884
    you can customize this function place your message instead of error see if result has any return value that means your mail has not been send successfully.
  • tsvtsv Member Posts: 49
    i am using 6.0 SP 1 Cronus DB.
    I tried to put the message box to see the valule of "Result" varaible like below
    WITH SMTPMailSetup DO
      Result :=
        Mail.Send(
          "SMTP Server",Authentication <> SMTPMailSetup.Authentication::Anonymous,"User ID", Password);
    Message('%1',Result);
    CLEAR(Mail);
    IF Result <> '' THEN
      ERROR(Text003,Result);
    

    It returned a blank message box...
    with regards,
    tsv
  • MBergerMBerger Member Posts: 413
    tsv wrote:
    i am using 6.0 SP 1 Cronus DB.
    I tried to put the message box to see the valule of "Result" varaible like below
    WITH SMTPMailSetup DO
      Result :=
        Mail.Send(
          "SMTP Server",Authentication <> SMTPMailSetup.Authentication::Anonymous,"User ID", Password);
    Message('%1',Result);
    CLEAR(Mail);
    IF Result <> '' THEN
      ERROR(Text003,Result);
    

    It returned a blank message box...
    Then i guess you are out of luck. The error you are getting is not detected during the send function, but afterwards when the function has already returned, so this error is not detectable.
Sign In or Register to comment.