[Cosm Logo]

Email Functions


CosmEmailSMTP

Syntax

#include "cosm/email.h"
s32 CosmEmailSMTP( const cosm_NET_ADDR smtp_server, const u16 port,
  const ascii * to, const ascii * from, const ascii * subject,
  const ascii * message, u32 length );

Description

Send SMTP email message of length length with subject using the given smtp_server host and port. The To: and From: fields will be set to to and from. SMTP is a 7-bit protocol so only plain text can be sent.

Return Values

COSM_PASS on success, or an error code on failure.

Errors

COSM_EMAIL_ERROR_TO
The TO address was rejected by the SMTP server.
COSM_EMAIL_ERROR_FROM
The FROM address was rejected by the SMTP server.
COSM_EMAIL_ERROR_HOST
The SMTP server specified was invalid.
COSM_EMAIL_ERROR_MESSAGE
Message length is nonzero, but message is NULL.
COSM_EMAIL_ERROR_NORELAY
The SMTP server specified does not permit relaying.
COSM_EMAIL_ERROR_ABORTED
Unable to complete transmission.

Example

  cosm_NET_ADDR smtp_server;
  ascii * server = "127.0.0.1";
  ascii * to = "foo@bar.com";
  ascii * from = "cosm@bar.com";
  ascii * subject = "Testing";
  ascii * message = "This is a test";
  u32 length;
  s32 error;

  length = CosmStrBytes( message );

  if ( CosmNetDNS( &smtp_server, 1, server ) == 1 )
  {
    error = CosmEmailSMTP( smtp_server, 25, to, from, subject,
      message, length );
    CosmPrint( "Email%.4s sent!\n",
      ( ( error == COSM_PASS ) ? "" : " NOT" ) );
  }
  else
  {
    CosmPrint( "DNS lookup error!\n" );
  }

© Copyright Mithral Communications & Design Inc. 1995-2024. All rights reserved. Mithral® and Cosm® are trademarks of Mithral Communications & Design Inc.
Document last modified: Jun 01, 2012