# Problems with e-mail inside a costatement

**URL:** <https://forums.digi.com/t/problems-with-e-mail-inside-a-costatement/9897>\
**Category:** Rabbit\
**Created:** [May 30, 2007, 3:47pm UTC](https://forums.digi.com/t/problems-with-e-mail-inside-a-costatement/9897 "2007-05-30T15:47:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndresGM](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@AndresGM](https://forums.digi.com/u/AndresGM)\
**Post date:** [May 30, 2007, 3:47pm UTC](https://forums.digi.com/t/problems-with-e-mail-inside-a-costatement/9897/1 "2007-05-30T15:47:28Z")

</div>

First of all, I tried the smtp sample “samples/tcpip/smtp/smtp.c” and everything worked fine, no problems here.

Then I introduced the smtp code inside this function :

```auto
//( previously defined macros )
#define FROM "agmangas@SmtpServerName.com"
#define TO "agmangas@gmail.com"
#define SUBJECT "Alarm Activated"
#define BODY "An alarm has been activated, visit the web for more information"

#define SMTP_SERVER "SmtpServerName"
#define USE_SMTP_AUTH
#define SMTP_VERBOSE
#define SMTP_DEBUG

```

```auto
void enviarMail(){

    while (ifpending(IF_DEFAULT) == IF_COMING_UP) {
    tcp_tick(NULL);
    }

    smtp_setauth ("xxxxx@SmtpServerName.com", "xxxxx");

    smtp_sendmail(TO, FROM, SUBJECT, BODY);

    while(smtp_mailtick()==SMTP_PENDING)
    continue;

    if(smtp_status()==SMTP_SUCCESS)
    printf("Message sent
");
    else
    printf("Error sending message
");
}

```

this function is called inside a costatement of the global code I�m developing, but it produced the following error :

```auto
SMTP: Resolving "SmtpServerName"
SMTP: Error resolving server(-2)

```

I tried writing the IP of the SMTP Server instead of its name, but there was a different error :

```auto
SMTP: Resolving xxx.xxx.xxx.xxx
SMTP: Opening to D595FD08:25
Error opening socket

```

This is how the main function looks like :

```auto
main(){

... Variables Initialization ...

[I][B]call[/B][/I]

while(1){

http_handler();  

[I][B]call[/B][/I]

costate {
waitfor(BitRdPortI(PDDR,5)==1);
waitfor(DelayMs(2000));
waitfor(BitRdPortI(PDDR,5)==1);
strcpy(AChar1,"Aon.gif");
[I][B]call[/B][/I]
waitfor(BitRdPortI(PDDR,5)==0);
strcpy(AChar1,"Aoff.gif");
}

... The same costatement repited 6 times with different port values ...

}//while
}//main

```

When I call “enviarMail()” in the places marked in blue, the function works, but it doesn�t work with the red ones, I can�t figure out how to fix it…

Any help would be appreciated, thanks in advance.

---

<div class="post-metadata">

**Author:** ![AndresGM](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@AndresGM](https://forums.digi.com/u/AndresGM)\
**Post date:** [May 31, 2007, 8:30am UTC](https://forums.digi.com/t/problems-with-e-mail-inside-a-costatement/9897/2 "2007-05-31T08:30:06Z")

</div>

Don�t know exactly how, but I fixed it 😉 , there was a problem with the maximum number of tcp sockets that could be open at the same time

---

<div class="post-metadata">

**Author:** ![zakhaku](https://avatars.discourse-cdn.com/v4/letter/z/a88e57/32.png) [@zakhaku](https://forums.digi.com/u/zakhaku)\
**Post date:** [September 3, 2007, 9:01am UTC](https://forums.digi.com/t/problems-with-e-mail-inside-a-costatement/9897/3 "2007-09-03T09:01:34Z")

</div>

> [@AndresGM;498](#):
>
> Don�t know exactly how, but I fixed it 😉 , there was a problem with the maximum number of tcp sockets that could be open at the same time

I am having the exact same problem. How did you solve it?

Thanks  
-Zak

---

<div class="post-metadata">

**Author:** ![AndresGM](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@AndresGM](https://forums.digi.com/u/AndresGM)\
**Post date:** [September 5, 2007, 3:24am UTC](https://forums.digi.com/t/problems-with-e-mail-inside-a-costatement/9897/4 "2007-09-05T03:24:13Z")

</div>

```auto
#define MAX_TCP_SOCKET_BUFFERS xx

```

I changed that parameter to 20 and everything worked OK 🙂
