Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7549337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:55:41+00:00 2026-05-30T09:55:41+00:00

I found the following function, which can send a mail : bool sendmail( char

  • 0

I found the following function, which can send a mail :

bool sendmail( char * smtpserver, char * from, char * to, char * subject, char * msg ) 
{ 
int         iProtocolPort        = 0; 
char        szSmtpServerName[64] = ""; 
char        szToAddr[64]         = ""; 
char        szFromAddr[64]       = "";
char        szBuffer[4096]       = ""; 
char        szLine[255]          = "";
char        szMsgLine[255]       = ""; 
SOCKET      hServer; 
WSADATA     WSData; 
LPHOSTENT   lpHostEntry; 
LPSERVENT   lpServEntry; 
SOCKADDR_IN SockAddr;  

// Load command-line args 
lstrcpyA( szSmtpServerName, smtpserver );
lstrcpyA( szToAddr, to ); 
lstrcpyA( szFromAddr, from );  

// Attempt to intialize WinSock (1.1 or later)
if ( WSAStartup( MAKEWORD( VERSION_MAJOR, VERSION_MINOR ), &WSData ) ) 
{     
    printf( "\nCannot find Winsock v%d.%d or later", VERSION_MAJOR, VERSION_MAJOR );    
    return false; 
} 
// Lookup email server's IP address. 
lpHostEntry = gethostbyname( szSmtpServerName ); 
if ( !lpHostEntry ) 
{    
    printf( "\nCannot find SMTP mail server %s", szSmtpServerName );     
    return false; 
}  

// Create a TCP/IP socket, no specific protocol 
hServer = socket( PF_INET, SOCK_STREAM, 0 ); 
if ( hServer == INVALID_SOCKET ) 
{     
    printf( "\nCannot open mail server socket!" );    
    return false;
}  

// Get the mail service port 
lpServEntry = getservbyname( "mail", 0 );  

// Use the SMTP default port if no other port is specified
if ( !lpServEntry ) iProtocolPort = htons( IPPORT_SMTP ); 
else iProtocolPort = lpServEntry->s_port;  

// Setup a Socket Address structure 
SockAddr.sin_family = AF_INET; 
SockAddr.sin_port   = iProtocolPort; 
SockAddr.sin_addr   = *( (LPIN_ADDR)*lpHostEntry->h_addr_list );  

// Connect the Socket 
if ( connect( hServer, ( PSOCKADDR ) &SockAddr, sizeof( SockAddr ) ) )
{    
    printf( "\nError connecting to Server socket!" );   
    return false; 
}  

// Receive initial response from SMTP server 
Check( recv( hServer, szBuffer, sizeof( szBuffer ), 0), "recv() Reply" );  

// Send HELO server.com 
sprintf_s( szMsgLine, "HELO %s%s", smtpserver, CRLF ); 
Check( send( hServer, szMsgLine, strlen( szMsgLine ), 0 ), "send() HELO" ); 
Check( recv( hServer, szBuffer, sizeof( szBuffer ), 0 ), "recv() HELO" ); 

// Send MAIL FROM: <sender@mydomain.com> 
sprintf_s( szMsgLine, "MAIL FROM:<%s>%s", from, CRLF );
Check( send( hServer, szMsgLine, strlen( szMsgLine ), 0 ), "send() MAIL FROM" ); 
Check( recv( hServer, szBuffer, sizeof( szBuffer ), 0 ), "recv() MAIL FROM" );  

// Send RCPT TO: <receiver@domain.com>     
sprintf_s( szMsgLine, "RCPT TO:<%s>%s", to, CRLF );    
Check( send( hServer, szMsgLine, strlen( szMsgLine ), 0 ), "send() RCPT TO" );     
Check( recv( hServer, szBuffer, sizeof( szBuffer ), 0 ), "recv() RCPT TO" ); 

// Send DATA 
sprintf_s( szMsgLine, "DATA%s", CRLF ); 
Check( send( hServer, szMsgLine, strlen( szMsgLine ), 0 ), "send() DATA" ); 
Check( recv( hServer, szBuffer, sizeof( szBuffer ), 0 ), "recv() DATA" );  

// Send Subject 
sprintf_s( szBuffer, "Subject: %s\n", subject ); 
Check( send( hServer, szBuffer, strlen( szBuffer ), 0 ), "send() Subject" );  

//Send From 
sprintf_s( szBuffer, "From: %s\n", from );
Check( send( hServer, szBuffer, strlen( szBuffer ), 0 ), "send() From" );  

//Send To 
sprintf_s( szBuffer, "To: %s\n\n", to ); 
Check( send( hServer, szBuffer, strlen( szBuffer ), 0 ), "send() To" ); 

//Check( send( hServer, szMsgLine, strlen( szMsgLine ), 0 ), "send() Attachment" );  
sprintf_s( szMsgLine, "%s%s", msg, CRLF );
Check( send( hServer, szMsgLine, strlen( szMsgLine ), 0 ), "send() message-line" );  

// Send blank line and a period 
sprintf_s( szMsgLine, "%s.%s", CRLF, CRLF );
Check( send( hServer, szMsgLine, strlen( szMsgLine ), 0 ), "send() end-message" );
Check( recv(  hServer, szBuffer, sizeof( szBuffer ), 0 ), "recv() end-message" );  

// Send QUIT 
sprintf_s( szMsgLine, "QUIT%s", CRLF );
Check( send( hServer, szMsgLine, strlen( szMsgLine ), 0 ), "send() QUIT" ); 
Check( recv( hServer, szBuffer, sizeof( szBuffer ), 0 ), "recv() QUIT" );  

// Close server socket and prepare to exit. 
closesocket( hServer );  

WSACleanup();  

return true; 
 } 

I am making an SQL query, and i would like to send the result in an email, but the result can be more than one line. So i don’t know, how could i send the whole result at once. The result of the SQL query will be stored in a struct( but if someone has a better a idee then i’m listening 🙂 ). So my question is, if is there a way to send this struct in email? Or how can i send every line which i get as a result in an email?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:55:42+00:00Added an answer on May 30, 2026 at 9:55 am

    At the side you would like to send your structure:

     // All sorts of initializations and stuff
     memcpy(yourbuffer,&yourstructure,sizeof(yourbuffer));
    

    At the other side:

     // Trivial stuff like receiving your buffer :-)
     memcpy(&yourstructure,yourbuffer,sizeof(yourstructure));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So: I have the following function, adapted from a formula found online, which takes
In the book Programming Collective Intelligence I found the following function to compute the
I used the following function I found online and it works perfectly. However, when
I found the following code in my team's project: Public Shared Function isRemoteDisconnectMessage(ByRef m
I saw the following function in a posting which allows one to order data
I current have the following which works well: channel.bind('pusher:subscription_succeeded', function(members) { members.each(set_status_online); }) function
For image scanning purposes, I'd like a pixel (which I can get from a
I found following piece of code written as a shell script to read from
I found the following AES encryption class from another question here. The class (as
In this question I found the following, but there are two errors which I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.