Home/Support/Support Forum/Using SMTP.c Program to Send Email with RCM5700
New and improved user forum site going live on 12/6 (All users will need to reset their password when the new forum is active)
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Using SMTP.c Program to Send Email with RCM5700

0 votes
Anybody use SMTP to send an email successfully?

I would like to send a simple text email from my RCM5700 microcontroller to my email account. I keep getting an error sending the message.

Here is what the SMTP_VERBOSE macro logs:

to:1507
from:14bf
subject:14a8
message:144B
SMTP: Resolving smtp.live.com
SMTP: Opening to 4137ACFE:24b
SMTP: Connected
SMTP: Read: 220 BLU0-SMTP49.phx.gbl Microsoft ESMTP MAIL Service, Version: 6.0.3
790.4675 ready at Sat, 15 Jun 2013 15:00:25 -0SMTP: Wrote EHLO cabin.mn.warpdri
veonline.com
SMTP: Read: 250-BLU0-SMTP49.phx.gbl Hello [24.236.46.37]
SMTP: Read: 250-TURN
SMTP: Read: 250-SIZE 41943040
SMTP: Read: 250-ETRN
SMTP: Read: 250-PIPELINING
SMTP: Read: 250-DSN
SMTP: Read: 250-ENHANCEDSTATUSCODES
SMTP: Read: 250-8bitmime
SMTP: Read: 250-BINARYMIME
SMTP: Read: 250-CHUNKING
SMTP: Read: 250-VRFY
SMTP: Read: 250-TLS
SMTP: Read: 250-STARTTLS
SMTP: Read: 250 OK
Error sending message

I'm communicating successfully with the mail server, but conks out at the end. I know I have to set up a SMTP connection through my email account settings, but when I try, it cannot find the SMTP server. The controller is on my LAN using a static IP address. How do I define the location of my controller's web server in terms of an email address: Mycontroller@Mydomain.com?

Here is my code (Sorry if hard to read):
/*******************************************************************************
smtp.c
Rabbit Semiconductor, 2000

A small program that uses the SMTP library
to send an e-mail.
*******************************************************************************/
#class auto


/***********************************
* Configuration *
*
*
* All fields in this section must *
* be altered to match your local *
* network settings. *
***********************************/

/*
* NETWORK CONFIGURATION
* Please see the function help (Ctrl-H) on TCPCONFIG for instructions on
* compile-time network configuration.
*/
#define TCPCONFIG 1
#define _PRIMARY_STATIC_IP "192.168.0.100"
#define _PRIMARY_NETMASK "255.255.255.0"
#define MY_GATEWAY "192.168.0.1"
#define MY_NAMESERVER "192.168.0.1"

#define MY_HOST "cabin"
#define MY_DOMAIN "domain.com"

/*
* These macros need to be changed to the appropriate values or
* the smtp_sendmail(...) call in main() needs to be changed to
* reference your values.
*/

#define SMTP_PORT 587

#define FROM "cabin@domain.com"
#define TO "My_Outlook_Email_Address@live.com"
#define SUBJECT "You've got mail!"
#define BODY "Visit the Rabbit Semiconductor web site.\r\n" \
"There you'll find the latest news about Dynamic C."

/*
* The SMTP_SERVER macro tells DCRTCP where your mail server is. This
* mail server MUST be configured to relay mail for your controller.
*
* This value can be the name or the IP address.
*/

#define SMTP_SERVER "smtp.live.com"

/*
* The SMTP_DOMAIN should be the name of your controller. i.e.
* "somecontroller.somewhere.com" Many SMTP servers ignore this
* value, but some SMTP servers use this field. If you have
* problems, turn on the SMTP_DEBUG macro and see were it is
* bombing out. If it is in the HELO command consult the
* person in charge of the mail server for the appropriate value
* for SMTP_DOMAIN. If you do not define this macro it defaults
* to the value in MY_IP_ADDRESS.
*
*/

#define SMTP_DOMAIN "cabin.domain.com"

/*
* The SMTP_VERBOSE macro logs the communications between the mail
* server and your controller. Uncomment this define to begin
* logging
*/

#define SMTP_VERBOSE

/*
* The USE_SMTP_AUTH macro enables SMTP Authentication, a method
* where the client authenticates with the server before sending
* a message. Call smtp_setauth() before smtp_sendmail() to set
* the username and password to use for authentication.
*/
#define USE_SMTP_AUTH

/*
* If the following macro is defined, then if SMTP authentication
* fails, the library will NOT attempt non-authenticated SMTP.
*/
#define SMTP_AUTH_FAIL_IF_NO_AUTH

/********************************
* End of configuration section *
********************************/

#memmap xmem
#use dcrtcp.lib
#use smtp.lib

void main()
{

// Start network and wait for interface to come up (or error exit).
sock_init();

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

sethostname(MY_HOST);
setdomainname(MY_DOMAIN);

#ifdef USE_SMTP_AUTH
smtp_setauth ("My_Outlook_SMTP_Username", "My_Outlook_SMTP_Password");
#endif

smtp_sendmail(TO, FROM, SUBJECT, BODY);

while(smtp_mailtick()==SMTP_PENDING)
continue;

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


}
asked Jun 17, 2013 in Rabbit Software by Chris1976 New to the Community (2 points)

Please log in or register to answer this question.

1 Answer

0 votes
Hello , With the below code I could able to send mail from the RCM6700. In this code , change network settings ,SMTP_TO and SMTP_SERVER addresses. It should send mail.


#class auto

#define TCPCONFIG 1
#define _PRIMARY_STATIC_IP "xxx.xxx.xxx.xxx"
#define _PRIMARY_NETMASK "xxx.xxx.xxx.xxx"
#define MY_GATEWAY "xxx.xxx.xxx.xxx"
#define MY_NAMESERVER "xxx.xxx.xxx.xxx"



#define SUBJECT "You've got mail!"
#define BODY "Visit the Rabbit Semiconductor web site.\r\n" \
"There you'll find the latest news about Dynamic C."


#define SMTP_FROM "tester@example.com"
#define SMTP_TO "xxx@xxxx.xxx"



#define SMTP_SERVER "xxx.xxx.xxx.xxx"

#ifndef SMTP_SERVER
#error "You must define SMTP_SERVER to your server's IP or hostname."
#endif
#ifndef SMTP_FROM
#error "You must define SMTP_FROM to a valid email address."
#endif
#ifndef SMTP_TO
#error "You must define SMTP_TO to your email address."
#endif

#memmap xmem
#use dcrtcp.lib
#use smtp.lib

void main()
{
// Start network and wait for interface to come up (or error exit).
sock_init_or_exit(1);

#ifdef USE_SMTP_AUTH
smtp_setauth (SMTP_AUTH_USER, SMTP_AUTH_PASS);
#endif

smtp_sendmail(SMTP_TO, SMTP_FROM, SUBJECT, BODY);

while(smtp_mailtick()==SMTP_PENDING)
continue;

if(smtp_status()==SMTP_SUCCESS)
printf("Message sent\n");
else
printf("Error sending message\n");
}
answered Jul 30, 2013 by cpigilam Veteran of the Digi Community (655 points)
Hi cpigilam,

Thanks very much for responding to my question.  I tried the code you posted and I get the same result.  I attempted to send an email to my gmail account and my hotmail account with no success.  I think the problem is in the authentication portion of the code.  I get responses from the mail server and after it sends a STARTTLS, there should be a AUTH PLAIN response. This is were the error occurs.  I tried shutting off my anti virus software, disabled the authentication in the code and used various ports - 25, 465, 587, etc.  I looked to see if there are settings on the gmail and hotmail side to allow emails from the microcontroller.

I'm stumped on this one.  About ready to give up on this problem, connect a wireless serial modem to send text messages and be finished with this project.

Thanks again for your input.
...