Author Topic: Work with email  (Read 10941 times)

Offline evgenik

  • Newbie
  • *
  • Posts: 18
    • View Profile
Work with email
« on: April 29, 2008, 03:36:44 PM »
Hi Mark.
I have started to work with email. These are my definitions in the program:

config.h:
    #define OUR_USER_DOMAIN                                  "my_domain.com"
    #define DEFAULT_DESTINATION_EMAIL_ADDRESS     "evgenik@sysmop.com"
    #define SMTP_PROVIDER_IP_ADDRESS                    { 194,158,229,11 }
    #define SMTP_PROVIDER_ADDRESS                        "mail.provider.com"

application.c:
static const NETWORK_PARAMETERS network_default = {
    (AUTO_NEGOTIATE | FULL_DUPLEX | RX_FLOW_CONTROL),     // usNetworkOptions - see driver.h for other possibilities
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},                                // ucOurMAC - when no other value can be read from parameters this will be used
    { 192, 168, 10, 233 },                                                     // ucOurIP - our default IP address
    { 255, 255, 255, 0 },                                                      // ucNetMask - Our default network mask
    { 192, 168, 0, 1 },                                                         // ucDefGW - Our default gateway
    { 192, 168, 10, 1 },                                                       // ucDNS_server - Our default DNS server
};
...
#ifdef SMTP_PARAMETERS
    {'U', 's', 'e', 'r', ' ', 'n', 'a', 'm', 'e', 0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {'P', 'a', 's', 's', ' ', 'w', 'o', 'r', 'd', 0,0},
    {'M', 'y', 'A', 'd', 'd', 'r', 'e', 's', 's', '@', 'u', 'T', 'a', 's', 'k', 'e', 'r', '.', 'c', 'o', 'm', 0,0,0,0,0,0,0,0,0,0},
    {'m', 'a', 'i', 'l', '.', 'p', 'r', 'o', 'v', 'i', 'd', 'e', 'r', '.', 'c', 'o', 'm', 0,0,0,0,0,0,0,0,0,0,0,0,0,0},

unsigned char ucSMTP_server[] = SMTP_PROVIDER_IP_ADDRESS;

app_hw_m5223x.h
    #define SENDERS_EMAIL_ADDRESS  "M52235EVB@uTasker.com"      // fictional Email address of the board being used
    #define EMAIL_SUBJECT                "M52235EVB Test"                  // Email subject
    #define EMAIL_CONTENT               "Hello!!\r\nThis is an email message from evgenik.\r\nI hope that you have received this test and have fun using the uTasker operating system with integrated TCP/IP stack.\r\r\nRegards evgenik!!";

#define SMTP_ACCOUNT_NAME           "smtp_user"
#define SMTP_PASSWORD                  "smtp_password"


I am not assured what data to me it is necessary to bring in these parameters. For example: SMTP_ACCOUNT_NAME and SMTP_PASSWORD must be at the same as in the PARs struct values (cUserName[8] and cUserPass[8]) or SMTP_PROVIDER_IP_ADDRESS value?
Help me to understand with it please.
Thanks.
Evgeni.

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Work with email
« Reply #1 on: April 29, 2008, 03:59:39 PM »
Hi Evgeni

Have you read the guide here?
http://www.utasker.com/docs/uTasker/uTaskerSMTP.PDF

The demo includes two method sof configuring the SMTP client. The first is a fixed (hard-coded) method based on the settings in config.h/app_hw_xxxxx.h. This method is used when SMTP_PARAMETERS is NOT defined.

If SMTP_PARAMETERS is defined, the parameters are taken from the parameter system (defaults being the set in application.c and configurable via the SMTP web page).

If your project is using DNS support, the address of the email provider will be resolved (from SMTP_PROVIDER_ADDRESS) otherwise (if no DNS support) it needs to be known (SMTP_PROVIDER_IP_ADDRESS).

It is more practical for first tests to use the parameter system method so that you can easily change values and experiment of necessary.

During the last year or so email providers have tightened security so it is generally necessary to use authentication and ensure that the email address of your device is within the correct domain (relaying is not often allowed).

Regards

Mark



Offline evgenik

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Work with email
« Reply #2 on: May 15, 2008, 09:38:09 AM »
Hi Mark.

I have read SMTP documentation, configured uTasker to use SMPT (same as in uTasker SMTP document), have received from provider my username, password, SMTP address, defined my GateWay, have placed them in the stPARS struct.
I want to send some emails. At the first attempt to send the email I receive a socket but as there is any failure the subsequent behind it of the email do not pass that SMPT is busy (ERROR_SMTP_IN_USE). How I can check up a return code which returns SMTP server (in Debug mode)?  All emails don't reach its final destination.
When I send only one message - all works well and the message comes to the addressee.
Whether there is an opportunity to send attachment file with email? (I need to send .scv file).

Thanks.
Evgeni.
« Last Edit: May 15, 2008, 01:18:25 PM by evgenik »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Work with email
« Reply #3 on: May 15, 2008, 10:02:13 PM »
Hi Evgeni

I sound as though the SMTP is basically working (since you can send a single message).
Once the message has been sent you will receive confirmation with the event SMTP_MAIL_SUCCESSFULLY_SENT via the user callback. Then it should be possible to send following mails.

If you get ERROR_SMTP_IN_USE when trying to connect it means that the close of the first mail connection has not yet terminated (and the SMTP_MAIL_SUCCESSFULLY_SENT has probably not been received yet).

The SMTP server sends only text and no attachments. This is something which would have to be added to enable you to send .scv files - I don't know how complicated this is at the moment. You could take a look at your normal Email client sending the text and attachement by recording its Ethernet communication (using Ethereal/WireShark) as a reference. Compare this with the simple email transmission and the additional steps should be visible.

How big is the attachement and where is it taken from (from file or from a buffer?)

Regards

Mark

Offline evgenik

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Work with email
« Reply #4 on: May 18, 2008, 07:18:04 AM »
Hi Mark.

I think, that the attached file is not sent directly and converted in binary format known to the email client program.
There can be an attached file it is necessary to write down in any coded kind? For example in MIME?
Can somebody will where find necessary information? I think by all such possibility of sending of files can be useful.

This is small part of body of email message that was attached file :
Content-type: multipart/mixed; boundary="----_=_NextPart_001_01C8B8A8.F0135738"
Thread-index: Aci4qO/ctwVHUjgSQheIQpENhabBSA==
X-MS-Has-Attach: yes
X-MS-TNEF-Correlator:
------_=_NextPart_002_01C8B8A8.F0135738
Content-Type: text/plain;
   charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

------_=_NextPart_001_01C8B8A8.F0135738
Content-Type: application/octet-stream;
   name="Book1.csv"
Content-Transfer-Encoding: base64
Content-Description: Book1.csv
Content-Disposition: attachment;
   filename="Book1.csv"

MQ0 K Mg0 K Mw0 K NA0 K NQ0 K Ng0 K Nw0 K OA0 K OQ0 K MTANCjExDQo=

------_=_NextPart_001_01C8B8A8.F0135738--



MQ0 K Mg0 K Mw0 K NA0 K NQ0 K Ng0 K Nw0 K OA0 K OQ0 K MTANCjExDQo= is body of file converted to binary format
http://email.about.com/cs/standards/a/mime.htm
May be this give any idea how I can add this information to your part of email information.

Thanks.
Evgeni.
« Last Edit: May 18, 2008, 01:42:25 PM by evgenik »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Work with email
« Reply #5 on: May 18, 2008, 02:53:50 PM »
Hi Evgeni

I have done similar (quick) tests using Thunderbird.
My feeling is that attachments can be sent fairly easily at the application level since they can be sent like this, embedded in the email content. The application defines the email content so can also define a content which inlcudes attachments.

The rules which I see at a first glance are:

1. A boundary is used to seperate each part (the message, and attachments(s). I don't know how this is generated but it may be random or maybe could be a fixed. It certainly shouldn't coincide with attachment content but this is probably so unlikely that it can be ignored.

2. If an attachment is plain text it can also be sent as plain text (text/plain with 7 bit tranfer encoding), but the sequence \r\n.\r\n (the end of email content) must be watched out for. It it occurs in the text it is replaced by \r\n..\r\n (2 x dot) and presumably removed by the receiver.

3. If the content is not 7-bit text it needs to be encoded - this is typically performed by using base64.

4. Before sending each content there are a few descriptors like "Content-Type:", "Content-Disposition:", "filename=" and  I would try to copy a simple case (there are probably lots of possible such things which are also not needed for a basic implementation) with minimum such descriptors which works reliably.

Possibly the most difficult decision is whether an attachment needs to be decoded or can be sent as plain text and I think that it may be best to simply send all attachements using base64 coding since this will probably avoid any possible errors.

This means that the position to add the support for emails with attachments is in the SMTP listener on the event SMTP_SEND_MESSAGE. This presenty sends a pre-defined message (in the demo project) but will need to be extended to build up the content as discussed above. Note that there is a routine fnEncode64() in webutils.c. This enables the encoding of strings (null terminated, or '&' terminated in keeping with HTTP and text content). This will have to be modified/extended to allow encoding of non-string type data!!

Good luck

Regards

Mark