Codesnippets > Network
FTP and Email Code Snippets
Kimaro:
Have any of you brilliant coders out there got any code snippets for FTP'ing or emailing with attachments. :nw:
MrTAToad:
I've got a Windows only bit of code for emails. It was originally used for work, but should still work :
--- Code: (glbasic) ---HINSTANCE hMail = NULL;
hMail = ::LoadLibraryA("MAPI32.DLL");
if (hMail == NULL)
{
MessageLastError();
SetCurrentDirectory((char *) ¤tDir);
return 1;
}
ULONG (PASCAL *lpfnSendMail)(ULONG, ULONG, MapiMessage*, FLAGS, ULONG);
(FARPROC&) lpfnSendMail = GetProcAddress(hMail, "MAPISendMail");
if (lpfnSendMail == NULL)
{
MessageLastError();
SetCurrentDirectory((char *) ¤tDir);
return 2;
}
MapiRecipDesc rec;
char szRName[] = "PlasWare Technical Support";
char szRAddress[] = "SMTP:support@plasware.co.uk";
char szSubject[] = "PlasWare Error Report";
SecureZeroMemory(&rec,sizeof(rec));
rec.ulRecipClass = MAPI_TO;
rec.lpszName = (emailName==NULL ? szRName : emailName);
rec.lpszAddress = (emailAddress==NULL ? szRAddress : emailAddress);
MapiMessage message;
SecureZeroMemory(&message,sizeof(message));
message.nRecipCount = 1;
message.lpRecips = &rec;
message.lpszSubject = (subject==NULL ? szSubject : subject);
message.lpszNoteText = ErrorText;
message.nFileCount=0; //(numAttachments>MAX_ATTACHMENTS ? MAX_ATTACHMENTS : numAttachments);
if (attachments)
{
register int loop;
SecureZeroMemory(&fileDesc,sizeof(fileDesc));
loop=0;
while ((attachments) && (strlen(attachments->fileName)>0) && loop<MAX_ATTACHMENTS)
{
fileDesc[loop].flFlags=0; // NOT an OLE object
fileDesc[loop].nPosition=-1; //loop;
fileDesc[loop].lpszPathName=attachments->fileName;
fileDesc[loop].lpszFileName=NULL;
fileDesc[loop].lpFileType=NULL; // Let the system cope with the extension
message.nFileCount++;
attachments++;
loop++;
}
message.lpFiles=(message.nFileCount>0 ? (lpMapiFileDesc) fileDesc : NULL);
}
else
{
message.lpFiles=NULL;
}
int nError;
if (showDialog == 1)
{
nError = lpfnSendMail(0, (ULONG) NULL, &message, MAPI_LOGON_UI | MAPI_DIALOG, 0);
}
else
{
nError = lpfnSendMail(0, (ULONG) NULL, &message, MAPI_LOGON_UI, 0);
}
if (nError != SUCCESS_SUCCESS && nError != MAPI_USER_ABORT && nError != MAPI_E_LOGIN_FAILURE)
{
windowWarnWithParam_S(WARNING_SENDMAILFAILED,false,
(nError==MAPI_E_INSUFFICIENT_MEMORY ? "Insufficient Memory" : \
nError==MAPI_E_AMBIGUOUS_RECIPIENT ? "Ambiguous recipient" : \
nError==MAPI_E_ATTACHMENT_NOT_FOUND ? "Attachment(s) not found" : \
nError==MAPI_E_ATTACHMENT_OPEN_FAILURE ? "Unable to open attachment" : \
nError==MAPI_E_BAD_RECIPTYPE ? "Invalid Parameters Passed" : \
nError==MAPI_E_FAILURE ? "Unspecified Error" : \
nError==MAPI_E_INVALID_RECIPS ? "Invalid Recipients" : \
nError==MAPI_E_TEXT_TOO_LARGE ? "Text in E-Mail is too large" : \
nError==MAPI_E_TOO_MANY_FILES ? "Too many attachments" : \
nError==MAPI_E_TOO_MANY_RECIPIENTS ? "Too many recipients" : \
nError==MAPI_E_UNKNOWN_RECIPIENT ? "Unknown recipients" : "Unknown"));
}
else
{
nError=ERROR_SUCCESS;
}
::FreeLibrary(hMail);
SetCurrentDirectory((char *) ¤tDir);
return (nError);
--- End code ---
For Linux and possibly Mac, you could call sendmail : http://www.hosting.com/support/linux/programming/sendmail/
Kimaro:
Thanks for the reply. I was wondering if there was anything that could be used from GLB possibly using third party dll's.
MrTAToad:
With Windows, you could get the current mail program from the registry and then call it... You dont need a DLL for using the previously mentioned code though!
With Linux, you could use SHELLCMD to call the appropriate program
Moru:
Or... you could just do it with GLBasics built in sockets commands... :-)
Navigation
[0] Message Index
[#] Next page
Go to full version