📄 send_email.c
字号:
// Send an e-mail to an SMTP host that will deliver or forward the messaage.
// This file and other embedded Ethernet and Internet code and resources are
// available from www.Lvr.com.
// Select a network configuration from \lib\tcpip\tcp_config.lib
// in the Dynamic C distribution.
#define TCPCONFIG 1
// Set the size of the DHCP socket buffer.
// Not required for Dynamic C v8 and higher.
//#define DHCP_SOCK_BUF_SIZE 900
// The rabbit's e-mail address.
// YOU MUST CHANGE THIS VALUE to match the e-mail address of your Rabbit module.
#define SENDER "rabbit1@lvr.com"
// The IP address or name of the SMTP server that will accept and deliver or
// forward the e-mail.
// YOU MUST CHANGE THIS VALUE to match the IP address or name of an SMTP server
// your Rabbit module can access.
// If you specify the SMTP server by name, you must define MY_NAMESERVER in
// tcpconfig.lib or in this application.
#define SMTP_SERVER "smtp.example.com"
// The Rabbit's name to send in the SMTP HELO command.
// If commented out, the HELO command will contain the rabbit's IP address.
// Some mail servers require a domain name.
//#define SMTP_DOMAIN "rabbit1@Lvr.com"
// Display communications with the SMTP server in Dynamic C's stdio window.
#define SMTP_DEBUG
// All C functions not declared as root go to extended memory.
#memmap xmem
// The dcrtcp library supports IP and TCP; the smtp library supports SMTP communications.
#use dcrtcp.lib
#use smtp.lib
char recipient[127];
char subject[127];
char body[255];
void create_message() {
// Create an e-mail message to send.
// The recipient's address.
strcpy(recipient, "jan@lvr.com");
// The message's Subject line.
strcpy(subject, "Hello from Rabbit");
// The message body
strcpy(body, "Rabbit test message.");
} // end create_message
void main() {
// Create and send a message.
create_message();
// Initialize the TCP/IP stack.
sock_init();
// Prepare to send the e-mail by initializing internal data structures
// using the recipient, sender, subject, and body.
smtp_sendmail(recipient, SENDER, subject, body);
// The smtp_mailtick() function handles communications with the mail server.
while(smtp_mailtick()==SMTP_PENDING)
continue;
// When smtp_mailtick() returns something other than SMTP_PENDING,
// detect the status and write a message to the console.
switch (smtp_status()) {
case SMTP_SUCCESS:
printf("The message has been sent.\n");
break;
case SMTP_TIME:
printf("Timeout error; message not sent.\n");
break;
case SMTP_UNEXPECTED:
printf("Invalid response from mail server; message not sent.\n");
break;
default:
printf("Error; message not sent.\n");
}
} // end main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -