Download presentation
Presentation is loading. Please wait.
1
SMTP CS176A Ramya Raghavendra ramya@cs.ucsb.edu
2
SMTP What is SMTP? –Simple Mail Transfer Protocol –SMTP server – every email client interfaces to send email –List of SMTP servers in transit - Check the headers on your email! Why talk directly to SMTP server? –Automation of emails in applications Without dependency on another email client –Real time notification of status Wrong ID, passwords etc
3
Example Consider Windows alternative like MAPI More complex More overhead
4
Multipart Messages But can we send multipart messages with attachments? –YES –SMTP is only a delivery mechanism, nothing to do with contents –RFCs on how to create multipart messages with attachments Your assignment –Simple text
5
SMTP commands HELO hostnameInitiate SMTP conversation MAIL From: Start. Sender’s email address RCPT To: Destination. Can be repeated. SIZE= Size of text. Good practice. DATAData will follow. Terminate with “.” QUITTerminates the connection. VRFY usernameVerify email. Can be disabled for security. Subject: Cc: Reply-To: Sent as a part of DATA stream.
6
For testing purposes Part 1 : –Please note: NO TURNIN Part 2: –To : command line argument –Subject: cs176aHW3ProgPart2 –Content: Name and Perm no.
7
Email Sender: Logic /* open the network connection */ sfd = smtpConnect(smtp_server,smtp_port); if (sfd == INVALID_SOCKET) { rc=(-1); goto cleanup; } // Send HELO smtpHelo(sfd,helo_domain); //Send “From” address smtpMailFrom(sfd,from); //Send “To” address smtpRcptTo(sfd);
8
Email Sender: Logic (Cont) //Send Data smtpData(sfd); //Send End-of-mail “.” smtpEom(sfd); //Send QUIT smtpQuit(sfd);
9
Connection to SMTP Server /* connect to SMTP server and returns the socket fd */ static SOCKET smtpConnect (char *smtp_server, int port) { SOCKET sfd; sfd=clientSocket(smtp_server,port); if (sfd == INVALID_SOCKET) { errorMsg("Could not connect to SMTP server \"%s\" at port %d\n", smtp_server,port); return (INVALID_SOCKET); } /* save it. we'll need it to clean up */ smtp_socket=sfd; return (sfd); }
10
One example /* SMTP: HELO */ static int smtpHelo(int sfd,char *helo_domain) { memset(buf,0,sizeof(buf)); (void) snprintf(buf,sizeof(buf)-1,"HELO %s\r\n",helo_domain); //Socket write function sockPuts(sfd,buf); return (smtpResponse(sfd)); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.