He probado este fragmento de codigo obtenido de la web de ajpdsoft para enviar emails y va de lujo pero mi duda es si hay forma de adjuntar datos adjuntos.
O si alguien conoce algun componente de delphi que sea capaz de mandar correo con archivos adjuntos me haría un gran favor.
Un ejemplo de utilización:
...
vtMensajeTexto := TStringList.Create;
vtMensajeTexto.Add('Cuerpo del mensaje.');
vtMensajeTexto.Add('');
vtMensajeTexto.Add('');
vtMensajeTexto.Add('');
vtMensajeTexto.Add('Por AjpdSoft');
if ConectarServidorEmail ('mail.servidor.com', 'usuario@ajpdsoft.com', 25) then
begin
if enviarEmail('mail.servidor.com', 'usuario@ajpdsoft.com', 'contraseña', 25,
'El asunto del email', vtmensajeTexto, true, 'emaildelemisor@ajpdsoft.com',
'Nombre del emisor', 'destinatario@ajpdsoft.com, copiacarbon@ajpdsoft.com) then
showmessage ('Mensaje enviado correctamente.')
else
showmessage ('El mensaje no se ha enviado.');
end
else
showmessage ('No se ha podido conectar con el servidor de email.');
...
Publicado:
Jue May 08, 2008 9:35 pm
alonsojpd Administrador/Moderador
Registrado: Sep 16, 2003 Mensajes: 2687
Asunto:
Hola Jose, en esta aplicación tienes un ejemplo de cómo insertar ficheros adjuntos a un email, incluye el código fuente en Delphi 6:
Si quieres hacerlo mediante MAPI, puedes utilizar esta otra función que lo que hace es abrirte el cliente de correo que tengas predeterminado, con una ventana de nuevo email, con el fichero adjuntado:
Código:
function enviarEmailClientePredeterminado (const asunto, cuerpo,
rutaFicheroAdjunto, nombreEmisor, emailEmisor,
nombreReceptor, emailReceptor : string) : integer;
var
message: TMapiMessage;
lpSender,
lpRecepient: TMapiRecipDesc;
FileAttach: TMapiFileDesc;
SM: TFNMapiSendMail;
MAPIModule: HModule;
begin
FillChar(message, SizeOf(message), 0);
with message do
begin
if (asunto <> '') then
begin
lpszSubject := PChar(asunto)
end;
if (cuerpo <> '') then
begin
lpszNoteText := PChar(cuerpo)
end;
if (emailEmisor <> '') then
begin
lpSender.ulRecipClass := MAPI_ORIG;
if (nombreEmisor = '') then
begin
lpSender.lpszName := PChar(emailEmisor)
end
else
begin
lpSender.lpszName := PChar(nombreEmisor)
end;
lpSender.lpszAddress := PChar('SMTP:' + emailEmisor);
lpSender.ulReserved := 0;
lpSender.ulEIDSize := 0;
lpSender.lpEntryID := nil;
lpOriginator := @lpSender;
end;
if (emailReceptor <> '') then
begin
lpRecepient.ulRecipClass := MAPI_TO;
if (nombreReceptor = '') then
begin
lpRecepient.lpszName := PChar(emailReceptor)
end
else
begin
lpRecepient.lpszName := PChar('')
end;
lpRecepient.lpszAddress := PChar('SMTP:' + emailReceptor);
lpRecepient.ulReserved := 0;
lpRecepient.ulEIDSize := 0;
lpRecepient.lpEntryID := nil;
nRecipCount := 1;
lpRecips := @lpRecepient;
end
else
begin
lpRecips := nil
end;
if (rutaFicheroAdjunto = '') then
begin
nFileCount := 0;
lpFiles := nil;
end
else
begin
FillChar(FileAttach, SizeOf(FileAttach), 0);
FileAttach.nPosition := Cardinal($FFFFFFFF);
FileAttach.lpszPathName := PChar(rutaFicheroAdjunto);
nFileCount := 1;
lpFiles := @FileAttach;
end;
end;
MAPIModule := LoadLibrary(PChar(MAPIDLL));
if MAPIModule=0 then
begin
Result := -1
end
else
begin
try
@SM := GetProcAddress(MAPIModule, 'MAPISendMail');
if @SM<>nil then
begin
Result := SM(0, Application.Handle, message, MAPI_DIALOG or
MAPI_LOGON_UI, 0);
end
else
begin
Result := 1
end;
finally
FreeLibrary(MAPIModule);
end;
end;
if Result<>0 then
begin
MessageDlg('Error al enviar email ('+IntToStr(Result)+').', mtError, [mbOk],
0)
end;
end;
Puede publicar nuevos temas en este foro No puede responder a temas en este foro No puede editar sus mensajes en este foro No puede borrar sus mensajes en este foro No puede votar en encuestas en este foro
Visita nuestro nuevo sitio web con programas y contenidos actualizados: Proyecto A