EmbeddedRelated.com
Forums
Memfault Beyond the Launch

SMTP Implementation

Started by seecwriter September 1, 2010
I'm using DC 9.25. Someone else mentioned that if the Sender parameter was an
empty
string, which is my case, that getting the DC Rabbit BIOS string is normal.

Another anomoly I found is that if I call smtp_mailtick() after SMTP
initialization, but

before sending any email, I can connect to the server. That is the printout in
my

original post. But none of the SMTP sample programs do that. They only call the
tick
after they call smtp_sendmail(). If I do it that way, my connect fails every
time.

Although, in either case, I can't send email.

Steve

________________________________
From: Tom Collins
To: "r..."
Sent: Fri, September 3, 2010 10:21:43 AM
Subject: Re: [rabbit-semi] SMTP Implementation

 
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
> I'm using DC 9.25. Someone else mentioned that if the Sender
> parameter was an empty
> string, which is my case, that getting the DC Rabbit BIOS string is
> normal.

I was wondering why you called it with an emtpy sender string but I
see now the documentation says you can leave out the sender to send a
mail without return address. This is really plain wrong, I wonder how
they thought that worked.

The smtp negotiation NEEDS a sender address; to send an "anonymous"
email the address can be left out of the header but it's still needed
for the conversation with the smtp-server. I don't have the smtp
source at hand here but I have a hunch the smtp library does
something weird when you give an empty string and ends up sending the
bios version (char* 0000). Or maybe whoever wrote that code thought
there would be no address checking by the smtp server so he could use
the bios version as an address for lack of anything better. Anyway
before troubleshooting any further, please try giving it a valid
sender address. I really don't see how it can work without one. And
as you can see in the verbose output, your smtp server is demanding a
valid sender address.

Even if you do manage to get an email out without a sender address in
the headers itself, it will most likely be deleted at the first spam-
check it comes across anyway. That kind of rfc-violating behaviour
really stopped working 10 years ago. :-)

Maurits.
What email address would I use for a sender? My unit doesn't get/have an email
address.

Steve

________________________________
From: Maurits van de Kamp
To: r...
Sent: Fri, September 3, 2010 12:04:38 PM
Subject: Re: [rabbit-semi] SMTP Implementation

 
I'm using DC 9.25. Someone else mentioned that if the Sender parameter was an
empty
>string, which is my case, that getting the DC Rabbit BIOS string is normal.

I was wondering why you called it with an emtpy sender string but I see now the
documentation says you can leave out the sender to send a mail without return
address. This is really plain wrong, I wonder how they thought that worked.

The smtp negotiation NEEDS a sender address; to send an "anonymous" email the
address can be left out of the header but it's still needed for the conversation
with the smtp-server. I don't have the smtp source at hand here but I have a
hunch the smtp library does something weird when you give an empty string and
ends up sending the bios version (char* 0000). Or maybe whoever wrote that code
thought there would be no address checking by the smtp server so he could use
the bios version as an address for lack of anything better. Anyway before
troubleshooting any further, please try giving it a valid sender address. I
really don't see how it can work without one. And as you can see in the verbose
output, your smtp server is demanding a valid sender address.

Even if you do manage to get an email out without a sender address in the
headers itself, it will most likely be deleted at the first spam-check it comes
across anyway. That kind of rfc-violating behaviour really stopped working 10
years ago. :-)

Maurits.
On 9/3/2010 4:07 PM, Steve Trigero wrote:
> What email address would I use for a sender? My unit doesn't get/have
> an email address.
>
> Steve

Use one your SMTP server will accept. Many only check the domain name.

>
>
> *From:* Maurits van de Kamp
> *To:* r...
> *Sent:* Fri, September 3, 2010 12:04:38 PM
> *Subject:* Re: [rabbit-semi] SMTP Implementation
>
>
>
>> I'm using DC 9.25. Someone else mentioned that if the Sender
>> parameter was an empty
>> string, which is my case, that getting the DC Rabbit BIOS string is
>> normal.
>
> I was wondering why you called it with an emtpy sender string but I
> see now the documentation says you can leave out the sender to send a
> mail without return address. This is really plain wrong, I wonder how
> they thought that worked.
>
> The smtp negotiation NEEDS a sender address; to send an "anonymous"
> email the address can be left out of the header but it's still needed
> for the conversation with the smtp-server. I don't have the smtp
> source at hand here but I have a hunch the smtp library does something
> weird when you give an empty string and ends up sending the bios
> version (char* 0000). Or maybe whoever wrote that code thought there
> would be no address checking by the smtp server so he could use the
> bios version as an address for lack of anything better. Anyway before
> troubleshooting any further, please try giving it a valid sender
> address. I really don't see how it can work without one. And as you
> can see in the verbose output, your smtp server is demanding a valid
> sender address.
>
> Even if you do manage to get an email out without a sender address in
> the headers itself, it will most likely be deleted at the first
> spam-check it comes across anyway. That kind of rfc-violating
> behaviour really stopped working 10 years ago. :-)
>
> Maurits.
--
------
Scott G. Henion, Consultant
Web site: http://SHDesigns.org
Rabbit libs: http://shdesigns.org/rabbit/
------
> What email address would I use for a sender? My unit doesn't get/
> have an email address.

Ah well that's why you need a valid email account that goes with the
smtp server you're using. :)

Technically, you can simply make up an address as long as it has an @
and at least one . in it. Before the days of standard spam
protection, this was enough. :)

However, these days this will often fail because most smtp-servers
check whether the domain really exists. So you should use an existing
domain name. However, if you use something like @hotmail.com, your
mail will very likely be rejected by some mailserver along the path
because of SPF-checking; meaning that the nameservers of hotmail.com
will be asked whether the smtp server you used is authorized to send
hotmail.com mail, which it probably isn't. There probably are plenty
of domain names that don't have strict SPF-records, an el-cheapo
provider's domain name will probably work.

Better though to use an email address that corresponds to the
provider that owns the mailserver. It would be even better to use a
really existing email address that you have access to, because that's
where failure messages will be sent to. If you use a nonexistent
address, they will go into oblivion.

Maurits.
On Sep 3, 2010, at 12:04 PM, Maurits van de Kamp wrote:
> The smtp negotiation NEEDS a sender address

That's incorrect. A NULL or empty sender address (MAIL FROM:<>) is valid, and is used all the time for generating bounce notifications.

http://en.wikipedia.org/wiki/Bounce_message
"...the empty path MAIL FROM:<>, used for many auto replies and especially all bounces."

-Tom
--- In r..., Steve Trigero wrote:
>
> What email address would I use for a sender? My unit doesn't get/have an email
> address.

Use a real email account. Make sure the server isn't one that requires POP3 before SMPT, in other words, they won't let you send an email until you first login and read emails (or at least check for new emails). This isnt' all that common, but if you happen to be on one of these servers, it can be tricky. I believe they log your IP address and set a timer. Once you read an email, you have x number of minutes to send emails from that IP address. If your computer is checking emails for this account and is at the same IP address, this can mask the problem. Your SMTP sends may always work, but once you put the unit out in the field at a different IP address, it may get rejected.

I had to put this functionality into a product I designed a few years ago. The end users could configure up to two email addresses for receiving notices from the unit, and one email address / user name / password for the outgoing (sending) account. If the unit tried to send and email and got rejected, it would then attempt to read emails (not storing or deleting them) and then re-send its outgoing email. I posted a picture of the email setup screen in the misc photos section. If you are hard-coding everything, you won't need this, but if you are selling a product to customers who have their own email addresses, you'll need a similar setup form.

On Sep 7, 2010, at 5:12 AM, ebrains2003 wrote:
> Make sure the server isn't one that requires POP3 before SMPT, in other words, they won't let you send an email until you first login and read emails (or at least check for new emails). This isnt' all that common, but if you happen to be on one of these servers, it can be tricky. I believe they log your IP address and set a timer. Once you read an email, you have x number of minutes to send emails from that IP address.

POP-before-SMTP is typically for supporting legacy clients. All SMTP servers in this day and age use authentication (SMTP AUTH) and it's probably the best way to go. Rabbit has supported SMTP AUTH since one of the early DC 9 releases.

You may also want to allow customers to configure the outbound SMTP port. It defaults to 25, but many servers will also accept email on port 587 (tcp/submission) as a way to get around ISPs that block direct connections to port 25 (or what to force you to use their SMTP server).

Finally, Google's Gmail service requires that you use TLS (encryption) for your SMTP connections. Dynamic C just started supporting client-side TLS in a recent DC 10 release, and I believe it includes samples that demonstrate sending email through a Gmail account.

I'd definitely follow ebrains2003's advice and provide a configuration screen in your app, with all of the fields you'd expect to see in an email client like Outlook.

-Tom
I switched to DC 9.62 to see if that would make a difference. There is a
difference, but it's not
a better difference.

This is what SMTP_VERBOSE produces:

                                                                               
to:bf93                                                                        
from:bf93                                                                      
subject:bfdc                                                                   
message:1F94                                                                   
SMTP: Opening to A0A00B9:19                                                    
Error opening socket.                                                          
 

The "to", "from", "subject", and "message" parameters appear to be pointers. And
I verified the content of those strings

in my code, so I'm sure if what's going on with verbose. But also notice that
the mail port is 19. What the....?
I compiled my code "as is". There were no changes made to go to DC 9.62 from
9.25. My code doesn't set
the mail port, it uses the default port, which was supposed to be 25, as it was
with DC 9.25.

Also note that, because of all the discussion as to whether a "From" address was
required or not,  I set the "From"
address to be the same as the "To" address. So "From" is set with a valid
address.

In any case, I see no improvement in going with DC 9.62. And one could make the
case that going to 9.62 is a
step backwards.

Steve

 

________________________________
From: Tom Collins
To: r...
Sent: Tue, September 7, 2010 6:30:28 AM
Subject: Re: [rabbit-semi] Re: SMTP Implementation

 
On Sep 7, 2010, at 5:12 AM, ebrains2003 wrote:
Make sure the server isn't one that requires POP3 before SMPT, in other words,
they won't let you send an email until you first login and read emails (or at
least check for new emails). This isnt' all that common, but if you happen to be
on one of these servers, it can be tricky. I believe they log your IP address
and set a timer. Once you read an email, you have x number of minutes to send
emails from that IP address.

POP-before-SMTP is typically for supporting legacy clients.  All SMTP servers in
this day and age use authentication (SMTP AUTH) and it's probably the best way
to go.  Rabbit has supported SMTP AUTH since one of the early DC 9 releases.

You may also want to allow customers to configure the outbound SMTP port.  It
defaults to 25, but many servers will also accept email on port 587
(tcp/submission) as a way to get around ISPs that block direct connections to
port 25 (or what to force you to use their SMTP server).

Finally, Google's Gmail service requires that you use TLS (encryption) for your
SMTP connections.  Dynamic C just started supporting client-side TLS in a recent
DC 10 release, and I believe it includes samples that demonstrate sending email
through a Gmail account.

I'd definitely follow ebrains2003's advice and provide a configuration screen in
your app, with all of the fields you'd expect to see in an email client like
Outlook.

-Tom
I found one problem. The SMTP library uses the TCP buffers defined by
MAX_TCP_SOCKET_BUFFERS.
I defined just enough buffers to handle all the tcp sockets that I allowed. So
when the smtp lib tried to
open a connection to the server there were no buffers available, so the
connection failed. My complaint is
that the SMTP manual says nothing about it requiring a tcp buffer. And none of
the smtp api functions
returns an error indicating the problem encountered. I had to enable debugging
in the smtp and tcp libraries
and step through the entire process to figure it out. I shouldn't have to do
that.
Be that as it may, I have another problem. I now connect, and the verbose
message says it sent my email,
(which I never get) and that's the last thing I hear from my program. I get a
virtual watchdog timeout calling

smtp_mailtick(). It's a good bet that a pointer has run amouk. Is there a size
limit to any of the buffers passed

to smtp_sendmail? The smtp manual doesn't give any buffer sizes. It just says to
use smtp_sendmail for "short"

messages, and to use smtp_sendmailxmem for "moderately long" messages. But never
defines what is "short"

and what is "moderate." Does that mean I can decide for myself what those mean?
My message is 64-bytes,

and the subject is around 32-bytes. Are those short or moderate lengths?

I'm in the process of modifying smtp.lib so I can try to find where it's getting
hung up. Any ideas on where I
should look?

Steve

________________________________
From: Steve Trigero
To: r...
Sent: Tue, September 7, 2010 3:05:10 PM
Subject: Re: [rabbit-semi] Re: SMTP Implementation

 
I switched to DC 9.62 to see if that would make a difference. There is a
difference, but it's not
a better difference.

This is what SMTP_VERBOSE produces:

                                                                               
to:bf93                                                                        
from:bf93                                                                      
subject:bfdc                                                                   
message:1F94                                                                   
SMTP: Opening to A0A00B9:19                                                    
Error opening socket.                                                          
 

The "to", "from", "subject", and "message" parameters appear to be pointers. And
I verified the content of those strings

in my code, so I'm sure if what's going on with verbose. But also notice that
the mail port is 19. What the....?
I compiled my code "as is". There were no changes made to go to DC 9.62 from
9.25. My code doesn't set
the mail port, it uses the default port, which was supposed to be 25, as it was
with DC 9.25.

Also note that, because of all the discussion as to whether a "From" address was
required or not,  I set the "From"
address to be the same as the "To" address. So "From" is set with a valid
address.

In any case, I see no improvement in going with DC 9.62. And one could make the
case that going to 9.62 is a
step backwards.

Steve

 

________________________________
From: Tom Collins
To: r...
Sent: Tue, September 7, 2010 6:30:28 AM
Subject: Re: [rabbit-semi] Re: SMTP Implementation

 
On Sep 7, 2010, at 5:12 AM, ebrains2003 wrote:
Make sure the server isn't one that requires POP3 before SMPT, in other words,
they won't let you send an email until you first login and read emails (or at
least check for new emails). This isnt' all that common, but if you happen to be
on one of these servers, it can be tricky. I believe they log your IP address
and set a timer. Once you read an email, you have x number of minutes to send
emails from that IP address.

POP-before-SMTP is typically for supporting legacy clients.  All SMTP servers in
this day and age use authentication (SMTP AUTH) and it's probably the best way
to go.  Rabbit has supported SMTP AUTH since one of the early DC 9 releases.

You may also want to allow customers to configure the outbound SMTP port.  It
defaults to 25, but many servers will also accept email on port 587
(tcp/submission) as a way to get around ISPs that block direct connections to
port 25 (or what to force you to use their SMTP server).

Finally, Google's Gmail service requires that you use TLS (encryption) for your
SMTP connections.  Dynamic C just started supporting client-side TLS in a recent
DC 10 release, and I believe it includes samples that demonstrate sending email
through a Gmail account.

I'd definitely follow ebrains2003's advice and provide a configuration screen in
your app, with all of the fields you'd expect to see in an email client like
Outlook.

-Tom

Memfault Beyond the Launch