Send email with BlitzMax

BlitzMax Forums/BlitzMax Programming/Send email with BlitzMax

Anybody has any send email routines for BlitzMax?

I've got something at home, I'll tidy it up and post it later for ya. :)

Thanks!

If your looking for a Windows only solution, I used the following C code for a DBPro plugin :

// Internet.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "Internet.h"
#include "mapi.h"
#include "io.h"

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    switch (ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:
		case DLL_THREAD_ATTACH:
		case DLL_THREAD_DETACH:
		case DLL_PROCESS_DETACH:
			break;
    }
    return TRUE;
}


// This is the constructor of a class that has been exported.
// see Internet.h for the class definition
DWORD sendEMailShort(char *emailAddress,
				char *emailName,
				 char *subject,
				 char *noteText)
{
	return (sendEMail(emailAddress,emailName,subject,noteText,NULL));
}

DWORD sendEMail(char *emailAddress,
				char *emailName,
				 char *subject,
				 char *noteText,
				 char *attachments)
{
char szFileName[MAX_PATH+1];
MapiFileDesc fileDesc[MAX_ATTACHMENTS];
HINSTANCE hMail;
ULONG (PASCAL *lpfnSendMail)(ULONG, ULONG, MapiMessage*, FLAGS, ULONG);
MapiRecipDesc rec;
MapiMessage message;
int nError;

	hMail=NULL;

	GetSystemDirectory(szFileName, sizeof(szFileName));
	strcat(szFileName, "\\MAPI32.DLL");
	if (_access(szFileName,00)!=0)
	{
		return (ERROR_MAPINOTFOUND);
	}

	if ((hMail=LoadLibrary("MAPI32.DLL"))==NULL)
	{
		FreeLibrary(hMail);
		return (ERROR_LOADDLL);
	}

	(FARPROC&) lpfnSendMail = GetProcAddress(hMail, "MAPISendMail");
	if (lpfnSendMail==NULL)
	{
		FreeLibrary(hMail);
		return (ERROR_SENDMAIL);
	}

	ZeroMemory(&message,sizeof(message));
	ZeroMemory(&rec,sizeof(rec));
	rec.ulRecipClass=MAPI_TO;
	rec.lpszName=(emailName==NULL ? "<<Enter EMail Address>>" : emailName);
	rec.lpszAddress=(emailAddress==NULL ? "<<Enter EMail Address>>" : emailAddress);

	message.nRecipCount=1;
	message.lpRecips=&rec;
	message.lpszSubject=subject;

	message.nFileCount=0;

	message.lpszNoteText=noteText;

	if (attachments)
	{
	register int pos,numAttach;
	char buffer[MAX_PATH+1];

		ZeroMemory(&fileDesc,sizeof(fileDesc));
		pos=0;
		numAttach=0;

		while (*(attachments+pos)!=(char) NULL && numAttach<MAX_ATTACHMENTS)
		{	
		register int index;

			ZeroMemory(&buffer,sizeof(buffer));
			index=0;

			while (*(attachments+pos)!=(char) '|' && 
				   *(attachments+pos)!=(char) NULL &&
	
				   index<sizeof(buffer)-1)
			{
				buffer[index]=(char) *(attachments+pos);
				index++;
				pos++;
			}

			pos++;
			if (strlen(buffer)>0 && access(buffer,00)==0)
			{
				fileDesc[numAttach].flFlags=0; // NOT an OLE object
				fileDesc[numAttach].nPosition=-1; //loop;
				fileDesc[numAttach].lpszPathName=(LPSTR) buffer;
				fileDesc[numAttach].lpszFileName=NULL;
				fileDesc[numAttach].lpFileType=NULL; // Let the system cope with the extension
				message.nFileCount++;
				numAttach++;
			}
		}
	}

	message.lpFiles=(message.nFileCount>0 ? (lpMapiFileDesc) fileDesc : NULL);

	nError=lpfnSendMail(0,(ULONG) NULL,&message,MAPI_LOGON_UI | MAPI_DIALOG,0);

	FreeLibrary(hMail);
	return (nError==SUCCESS_SUCCESS ? ERROR_SUCCESS : \
		    nError==MAPI_USER_ABORT ? ERROR_USERABORT : \
			nError==MAPI_E_LOGIN_FAILURE ? ERROR_LOGINFAILURE : \
			nError==MAPI_E_INSUFFICIENT_MEMORY ? ERROR_MEMERROR : \
			nError==MAPI_E_AMBIGUOUS_RECIPIENT ? ERROR_AMBIGRECIP : \
			nError==MAPI_E_ATTACHMENT_NOT_FOUND ? ERROR_FILENOTFOUND : \
			nError==MAPI_E_ATTACHMENT_OPEN_FAILURE ? ERROR_FILEOPEN : \
			nError==MAPI_E_BAD_RECIPTYPE ? ERROR_INVALIDPARAM : \
			nError==MAPI_E_FAILURE ? ERROR_UNKNOWN : \
			nError==MAPI_E_INVALID_RECIPS ? ERROR_INVALIDRECIP : \
			nError==MAPI_E_TEXT_TOO_LARGE ? ERROR_TEXTTOOLARGE : \
			nError==MAPI_E_TOO_MANY_FILES ? ERROR_TOOMANYFILES : \
			nError==MAPI_E_TOO_MANY_RECIPIENTS ? ERROR_TOOMANYRECIP : \
			nError==MAPI_E_UNKNOWN_RECIPIENT ? ERROR_UNKNOWNRECIP : ERROR_UNKNOWN);
}


It should be easy enough to convert to BlitzMax

Couldn't you just use the Sockets mod?

Sure he could, but he'd have to manually implement the required RFCs for SMTP and MIME attachments.