EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

SMTP Implementation

Started by seecwriter September 1, 2010
I've added smtp to my app. I've turned on SMTP_VERBOSE, and below is
a short snippet of the printout. All this happens during power-up. I
haven't even tried to send an email yet. My question is, where is
the "Invalid address" coming from? What address is it expecting.

I initialized smtp with the following:

smtp_setserver_ip(inet_addr("10.10.0.185"));
strcpy(email_adrs, "m...@mydomain.com");

Did I miss something in the initialization?

==========================================
SMTP: Opening to 0A0A00B9:25
SMTP: Connected
SMTP: Read: 220 CMDCEXCAHT01.comtechtel.com Microsoft ESMTP MAIL Service ready at Wed, 1 Sep 2010 19:15:23 - 0400
SMTP: Wrote HELO 10.250.5.51
SMTP: Read: 250 CMDCEXCAHT01.comtechtel.com Hello [10.250.5.51]
SMTP: Wrote MAIL FROM:
SMTP: Read: 501 5.1.7 Invalid address
SMTP: Socket unexpectedly closed!
SMTP: Socket unexpectedly closed!
SMTP: Socket unexpectedly closed!
SMTP: Socket unexpectedly closed!
SMTP: Socket unexpectedly closed!
Steve

Op Sep 2, 2010, om 1:31 AM heeft seecwriter het volgende geschreven:

> strcpy(email_adrs, "m...@mydomain.com");

(...)
> SMTP: Wrote MAIL FROM:
> SMTP: Read: 501 5.1.7 Invalid address

The SMTP library is using "DynamiCUniversal Rabbit BIOS Version 9.24"
as email address, which is obviously invalid. Usually when this
string appears somewhere unexpectidly, it's because of an invalid
pointer (the bios version string is probably written somewhere near
address 0000 in ram) :)

So, before you strcpy your address into the email_adrs string, are
you sure that variable is pointing to allocated space large enough to
house that address, and that you correctly pass this string to the
smtp function as from-address? As long as the address is fixed in
code, you could also simply say:
email_adrs = "m...@mydomain.com";

..which will point the string to the piece of program code with the
address in it.

Maurits.

--- In r..., "seecwriter" wrote:
>
> I've added smtp to my app. I've turned on SMTP_VERBOSE, and below is
> a short snippet of the printout. All this happens during power-up. I
> haven't even tried to send an email yet. My question is, where is
> the "Invalid address" coming from? What address is it expecting.
>

Can you post more of the code?

Have you tried the SMTP.C sample? How are you calling smtp_sendmail()?

If you printf your "from" address right before the call to smtp_sendmail(), does it dump what you're expecting it to?

-Tom

char email_adrs[65];

I don't think email_adrs is the issue. I believe its been declared
with plenty of space.

I did find a bad pointer for the "subject" parameter of
smtp_sendmail(). I corrected it, but it made no difference.

I also noticed that, if I don't put smtp_mailtick() in the main loop
I never connect to the mail server. In fact all those verbose print
outs, are produced just by calling smtp_mailtick() in my mail loop.
I haven't yet tried to send any email.

If I only call smtp_mailtick() after calling smtp_sendmail(), like
the sample programs do, I never connect to the server, and I get a
SMTP_NOSOCK error.

Should I be calling smtp_mailtick() in the main loop, or only when
sending an email?

Steve

--- In r..., Maurits van de Kamp wrote:
> Op Sep 2, 2010, om 1:31 AM heeft seecwriter het volgende geschreven:
>
> > strcpy(email_adrs, "myname@...");
>
> (...)
> > SMTP: Wrote MAIL FROM:
> > SMTP: Read: 501 5.1.7 Invalid address
>
> The SMTP library is using "DynamiCUniversal Rabbit BIOS Version 9.24"
> as email address, which is obviously invalid. Usually when this
> string appears somewhere unexpectidly, it's because of an invalid
> pointer (the bios version string is probably written somewhere near
> address 0000 in ram) :)
>
> So, before you strcpy your address into the email_adrs string, are
> you sure that variable is pointing to allocated space large enough to
> house that address, and that you correctly pass this string to the
> smtp function as from-address? As long as the address is fixed in
> code, you could also simply say:
> email_adrs = "myname@...";
>
> ..which will point the string to the piece of program code with the
> address in it.
>
> Maurits.
>

This is my procedure.

int SendEmail( char *buf )
{
  USL end;
  int ok, errCode;
  ok = 0;
 
// Need working ethernet interface.
  if ( ifpending(IF_ETH0) != IF_UP )  return ok;
  
  if ( (strlen(email_adrs) > 0) && (strlen(buf) > 0) ) {
    end = MS_TIMER + 500L;
    smtp_sendmail( email_adrs, "" , id_string, buf );
    errCode = smtp_mailtick();
    while ( errCode == SMTP_PENDING ) {
      errCode = smtp_mailtick();
      if ( MS_TIMER > end ) {
        break;
      }
    }
    if ( errCode == SMTP_SUCCESS ) {
      ok = 1;
    }
  }
  return ok;
}

________________________________
From: tomcollinsaz
To: r...
Sent: Thu, September 2, 2010 8:42:53 AM
Subject: [rabbit-semi] Re: SMTP Implementation

 
--- In r..., "seecwriter" wrote:
>
> I've added smtp to my app. I've turned on SMTP_VERBOSE, and below is
> a short snippet of the printout. All this happens during power-up. I
> haven't even tried to send an email yet. My question is, where is
> the "Invalid address" coming from? What address is it expecting.
>

Can you post more of the code?

Have you tried the SMTP.C sample? How are you calling smtp_sendmail()?

If you printf your "from" address right before the call to smtp_sendmail(), does
it dump what you're expecting it to?

-Tom
This is what works flawlessly to me here. It may help there:

if(resolve(e_server)!=0)
{
     
err_rd=0;
     
smtp_setserver(e_server);
     
smtp_setauth(user,pword);
      strcpy(print_buf,"\n\r   ESMTP Configuration Test.\n\r\0");
      strcat(print_buf,"   This e mail address is being used to receive automatic reports.\n\r\n\r   Result:
SUCCESS\0");
      smtp_sendmail(receiver, sender, SUBJECT_CONF,
print_buf);
     
while(smtp_mailtick()==SMTP_PENDING &&
err_rd<120000)
       {
       
err_rd++;
       
continue;
      
}
      if(err_rd<120000
&& smtp_status()==SMTP_SUCCESS)
      
{
        // SUCCESS
      
}       else       {        //BIG FAIL       }}
--- Em qui, 2/9/10, Steve Trigero escreveu:

De: Steve Trigero
Assunto: Re: [rabbit-semi] Re: SMTP Implementation
Para: r...
Data: Quinta-feira, 2 de Setembro de 2010, 13:11

 

This is my procedure.
 
int SendEmail( char *buf )
{
  USL end;
  int ok, errCode;
  ok = 0;
 
// Need working ethernet interface.
  if ( ifpending(IF_ETH0) != IF_UP )  return ok;
  
  if ( (strlen(email_adrs) > 0) && (strlen(buf) > 0) ) {
    end = MS_TIMER + 500L;
    smtp_sendmail( email_adrs, "" , id_string, buf );
    errCode = smtp_mailtick();
    while ( errCode == SMTP_PENDING ) {
      errCode = smtp_mailtick();
      if ( MS_TIMER > end ) {
        break;
      }
    }
    if ( errCode == SMTP_SUCCESS ) {
      ok = 1;
    }
  }
  return ok;
}

From: tomcollinsaz
To: r...
Sent: Thu, September 2, 2010 8:42:53 AM
Subject: [rabbit-semi] Re: SMTP Implementation

 

--- In r..., "seecwriter" wrote:
>
> I've added smtp to my app. I've turned on SMTP_VERBOSE, and below is
> a short snippet of the printout. All this happens during power-up. I
> haven't even tried to send an email yet. My question is, where is
> the "Invalid address" coming from? What address is it expecting.
>

Can you post more of the code?

Have you tried the SMTP.C sample? How are you calling smtp_sendmail()?

If you printf your "from" address right before the call to smtp_sendmail(), does it dump what you're expecting it to?

-Tom
Actually, mine has nothing so different from your implementation.The only difference is that you are passing a null string as the sender. Try to pass a string with the sender e mail address instead. It should work.

--- Em sex, 3/9/10, Alexandre Kremer escreveu:

De: Alexandre Kremer
Assunto: Re: [rabbit-semi] Re: SMTP Implementation
Para: r...
Data: Sexta-feira, 3 de Setembro de 2010, 9:45

 

This is what works flawlessly to me here. It may help there:

if(resolve(e_server)!=0)
{
     
err_rd=0;
     
smtp_setserver(e_server);
     
smtp_setauth(user,pword);
      strcpy(print_buf,"\n\r   ESMTP Configuration Test.\n\r\0");
      strcat(print_buf,"   This e mail address is being used to receive automatic reports.\n\r\n\r   Result:
SUCCESS\0");
      smtp_sendmail(receiver, sender, SUBJECT_CONF,
print_buf);
     
while(smtp_mailtick()==SMTP_PENDING &&
err_rd<120000)
       {
       
err_rd++;
       
continue;
      
}
      if(err_rd<120000
&& smtp_status()==SMTP_SUCCESS)
      
{
        // SUCCESS
      
}       else       {        //BIG FAIL       }}
--- Em qui, 2/9/10, Steve Trigero
escreveu:

De: Steve Trigero
Assunto: Re: [rabbit-semi] Re: SMTP Implementation
Para: r...
Data: Quinta-feira, 2 de Setembro de 2010, 13:11

 

This is my procedure.
 
int SendEmail( char *buf )
{
  USL end;
  int ok, errCode;
  ok = 0;
 
// Need working ethernet interface.
  if ( ifpending(IF_ETH0) != IF_UP )  return ok;
  
  if ( (strlen(email_adrs) > 0) && (strlen(buf) > 0) ) {
    end = MS_TIMER + 500L;
    smtp_sendmail( email_adrs, "" , id_string, buf );
    errCode = smtp_mailtick();
    while ( errCode == SMTP_PENDING ) {
      errCode = smtp_mailtick();
      if ( MS_TIMER > end ) {
        break;
      }
    }
    if ( errCode == SMTP_SUCCESS ) {
      ok = 1;
    }
  }
  return ok;
}

From: tomcollinsaz
To: r...
Sent: Thu, September 2, 2010 8:42:53 AM
Subject: [rabbit-semi] Re: SMTP Implementation

 

--- In r..., "seecwriter" wrote:
>
> I've added smtp to my app. I've turned on SMTP_VERBOSE, and below is
> a short snippet of the printout. All this happens during power-up. I
> haven't even tried to send an email yet. My question is, where is
> the "Invalid address" coming from? What address is it expecting.
>

Can you post more of the code?

Have you tried the SMTP.C sample? How are you calling smtp_sendmail()?

If you printf your "from" address right before the call to smtp_sendmail(), does it dump what you're expecting it to?

-Tom

 
> The only difference is that you are passing a null string as the
> sender.

..which means the smtp library will use the text located as 0000 as
sender, which is the bios version. Mystery solved. :) Sorry I didn't
notice this until you said so, I stopped reading after the original
poster assured me that the sender address was not the problem, where
the verbose information clearly showed it was. :)

Maurits.
"" being the null string is not a NULL pointer. "" does not point to 0. Unfortunately the term null string is maybe being confused with NULL pointer. I tend to use the phrase empty string because it's empty ("" as opposed to "abc") but not a NULL pointer.

Bill

--- In r..., Maurits van de Kamp wrote:
>
> > The only difference is that you are passing a null string as the
> > sender.
>
> ..which means the smtp library will use the text located as 0000 as
> sender, which is the bios version. Mystery solved. :) Sorry I didn't
> notice this until you said so, I stopped reading after the original
> poster assured me that the sender address was not the problem, where
> the verbose information clearly showed it was. :)
>
> Maurits.
>

On Sep 1, 2010, at 4:31 PM, seecwriter wrote:
> SMTP: Wrote MAIL FROM:

Does that mean you're using DC 9.24? Compare SMTP.LIB from DC 9.62 to the version you're using and see if there were any bug fixes.

-Tom

The 2024 Embedded Online Conference