 |
Club Builder Foro de C++Builder en español
|
| Ver tema anterior :: Ver tema siguiente |
| Autor |
Mensaje |
Touchsoftwares Master


Registrado: 16 Dic 2002Mensajes: 869Ubicación: MEXICO Playa del Carmen
|
Publicado: Jue 31 Mar, 2011 4:34 am Asunto: Compro Componente para enviar archivos a travez de cualquier |
|
|
Compro Componente para enviar archivos a travez de cualquier email
Ya me fastidie!, no logro hacer que ese &/%&% indy 9.0.14 funcione en Builder 6 y el tiempo me esta comiendo, quien de ustedes me vende un codigo que funcione para envio de mails, si es una dll o algo asi ..mejor
Saludos!
El tiempo es dinero y ya no tengo tiempo para perder con ese tema..Gracias! _________________ Ing. Gabriel Góngora Navarrete
TouchSoftwares Inc
http://www.touchsoftwares.com |
|
| Volver arriba |
|
 |
Angel Master


Registrado: 15 Abr 2003Mensajes: 2311Ubicación: Toledo (España)
|
|
| Volver arriba |
|
 |
juanma Cmdr

Registrado: 17 Nov 2005Mensajes: 127Ubicación: Almeria - España
|
Publicado: Jue 31 Mar, 2011 10:43 am Asunto: |
|
|
Hola Gabriel,
Hace tiempo que codifiqué esto y la parte de envio por outlook, en su momento la usé y funcionaba bien, pero últimamente solo envio los mensajes con los componentes indy, mi IDE es el CB2007 (también lo probé en su momento con el 2010), por lo que me imagino que solo te servirá la parte de envio a través del outlook, como verás son dos clases diferentes, con lo que me imagino será facil eliminar todo lo del indy que será incompatible con lo que tienes.
De todas formas hay bastante código que podrás usar como referencia.
Saludos,
Juanma
el .hpp
| Código: | //---------------------------------------------------------------------------
#ifndef cMdMsgH
#define cMdMsgH
// en Nucleo -> #define MdINDY | MdMAPI
#include <Classes>
//#include <IdBaseComponent>
//#include <IdComponent>
//#include <IdMessage>
//#include <IdMessageClient>
//#include <IdSMTP>
//#include <IdTCPClient>
//#include <IdTCPConnection>
//#include <IdText>
//#include <IdAttachmentFile>
//#include <IdGlobalProtocols> //4gettypemime
//-----------------------------
// #ifdef MdMAPI
#include <mapi>
class MyMsg {
MapiMessage MapiMsg;
MapiRecipDesc RecipInfo;
MapiFileDesc lpFiles;
LPMAPILOGON pMAPILogon;
LPMAPILOGOFF pMAPILogoff;
LPMAPISENDMAIL pMAPISendMail;
LHANDLE hSession;
HINSTANCE hMAPILib;
char aPathS[MAX_PATH + 1], aFileS[MAX_PATH + 1];
bool lLb, lFc;
AnsiString cBdy;
public:
MyMsg();
~MyMsg();
bool lOK;
int nE;
void Destino(AnsiString);
void Asunto(AnsiString);
void AttachF(AnsiString);
void AddText(AnsiString);
void ClearText();
void Urgente();
bool Envia();
};
void SendByOutLook(String cD, String cA, String cB, String cF);
// #endif
// #ifdef MdINDY
//#include "IdExplicitTLSClientServerBase.hpp"
#include <IdBaseComponent>
#include <IdComponent>
#include <IdMessage>
#include <IdMessageClient>
#include "IdSMTPBase.hpp"
#include <IdSMTP>
#include <IdPOP3>
#include <IdTCPClient>
#include <IdTCPConnection>
#include <IdText>
#include <IdAttachmentFile>
#include <IdGlobalProtocols> //4gettypemime
//------------------- Indy ---
class IdMsg {
TIdSMTP *IdSMTP;
TIdMessage *IdMs;
TIdText *txp;
int npt, nri;
public:
IdMsg();
~IdMsg();
bool lOK;
int nE;
void IniciaOrg(String cO, String cU, String cP, String cB);
void SetSrv(String cS, int nP);
void Destino(String);
void AddDestino(String);
void Asunto(String);
void AttachF(String);
void AddText(String);
void AddTList(TStrings *);
void ClearText();
void IsHTML(TStrings *);
void Urgente();
bool Envia();
};
// #endif
//---------------------------------------------------------------------------
#endif
|
el .cpp
| Código: | //---------------------------------------------------------------------------
#include <vcl>
#pragma hdrstop
#include "cMdMsg.h"
// #ifdef MdMAPI
#include <ComObj> //para usar object outlook
// #endif
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
//
// Usos:
/*
void __fastcall TfInicial::EnviaMsg()
{
String cMs;
std::auto_ptr<IdMsg> IdMs(new IdMsg());
IdMs->IniciaOrg(xAp.cCD, xAp.cUs, xAp.cPw,"");
if (opU->Checked){
cMs = opU->Caption + ". ";
IdMs->Urgente(); //IdMs->Priority = mpHigh;
}
IdMs->Asunto(cMs + MLG.TextLg("Msg de") + " " +
tQu->Text + ", (" + lbFc->Caption + " " +lbHr->Caption + ")");
if (opT->Checked)
cMs += "( " + opT->Caption + " )";
IdMs->AddText(StringOfChar('-', 42));
IdMs->AddText(MLG.TextLg("De") + ":\t" + tQu->Text);
IdMs->AddText(MLG.TextLg("Empresa") + ":\t" + tEm->Text);
IdMs->AddText(MLG.TextLg("Teléfono") + ":\t" + tTl->Text);
IdMs->AddText(StringOfChar('-', 42));
IdMs->AddText(MLG.TextLg("Mensaje") +": "+ cMs);
IdMs->AddText(tMs->Text);
IdMs->AddText(StringOfChar('-', 42));
IdMs->AddText(MLG.TextLg("Enviado por") + ": " + tEp->Text);
IdMs->AddText("[" + lbFc->Caption + " " +lbHr->Caption +
", " + NameOfPC() + "]");
IdMs->Destino(cDs);
if (IdMs->Envia()){
SBox("Mensaje envidado a " + xTo->Text, 2);
Close();
} else
SBox("Error de comunicación", 1);
}
//---------------------------------------------------------------------------
void __fastcall TfInicial::MAPIMsg()
{
MyMsg Msg;
String cAs, cMs;
int nR;
if (opU->Checked)
cMs = opU->Caption + ". ";
if (Msg.lOK) {
cAs = cMs + MLG.TextLg("Msg de") + " " + tQu->Text +
", (" + lbFc->Caption + " " + lbHr->Caption + ")";
Msg.Destino(cDs);
Msg.Asunto(cAs);
if (opT->Checked)
cMs += "( " + opT->Caption + " )\r\n";
Msg.AddText(StringOfChar('-', 42));
Msg.AddText(MLG.TextLg("De") + ":\t" + tQu->Text);
Msg.AddText(MLG.TextLg("Empresa") + ":\t" + tEm->Text);
Msg.AddText(MLG.TextLg("Teléfono") + ":\t" + tTl->Text);
Msg.AddText(StringOfChar('-', 42));
Msg.AddText(MLG.TextLg("Mensaje") + ": " + cMs);
Msg.AddText(tMs->Text);
Msg.AddText(StringOfChar('-', 42));
Msg.AddText(MLG.TextLg("Enviado por") + ": " + tEp->Text);
Msg.AddText("[" + lbFc->Caption + " " + lbHr->Caption +
", " + NameOfPC() + "]");
if (Msg.Envia()) {
SBox("Mensaje en salida para " + xTo->Text, 2);
Close();
} else
SBox("Error MAPI: " + IntToStr(Msg.nE), 1);
} else
SBox("Error inicializando MAPI", 1);
}
//---------------------------------------------------------------------------
void __fastcall TfInicial::MensajeOLK()
{
String cCb, cAs, cMs;
cCb = (StringOfChar('-', 42) + "\r\n");
cCb += (MLG.TextLg("De") + ":\t" + tQu->Text + "\r\n");
cCb += (MLG.TextLg("Empresa") + ":\t" + tEm->Text + "\r\n");
cCb += (MLG.TextLg("Teléfono") + ":\t" + tTl->Text + "\r\n");
cCb += (StringOfChar('-', 42) + "\r\n");
if (opU->Checked) cMs = opU->Caption + ". ";
cAs = cMs + MLG.TextLg("Msg de") + " " + tQu->Text +
", (" + lbFc->Caption + " " + lbHr->Caption + ")";
if (opT->Checked) cMs += "( " + opT->Caption + " )\r\n";
cMs += (MLG.TextLg("Mensaje") + ": " + cMs + "\r\n");
cMs += (tMs->Text + "\r\n");
cMs += (StringOfChar('-', 42) + "\r\n");
cMs += (MLG.TextLg("Enviado por") + ": " + tEp->Text + "\r\n");
cMs += ("[" + lbFc->Caption + " " + lbHr->Caption +
", " + NameOfPC() + "]");
SendByOutLook(cDs, cAs, cCb+cMs, "");
MessageBeep(0);
}
//---------------------------------------------------------------------------
*/
// #ifdef MdINDY
// Indy 10 -> TIdSMTP
//---------------------------------------------------------------------------
IdMsg::IdMsg()
{
IdSMTP = new TIdSMTP(Application->Owner);
IdMs = new TIdMessage(Application->Owner);
npt = nri = 0;
IdSMTP->Host = "name.server.net";
}
//---------------------------------------------------------------------------
IdMsg::~IdMsg()
{
IdMs->Clear(); //opcion??
delete IdMs;
delete IdSMTP;
npt = 0;
}
//---------------------------------------------------------------------------
void IdMsg::IniciaOrg(String cO, String cU, String cP, String cB)
{
//IdMs->Clear();
IdMs->From->Address = cO;
if (cU.Length()>0) {
IdSMTP->Username = cU;
IdSMTP->Password = cP;
IdSMTP->AuthType = atDefault;
// IdSMTP->AuthType = satDefault; //en 2010
}
if (cB.Length()>0) {
TIdEMailAddressItem * bcc = IdMs->BccList->Add();
bcc->Address = cB;
}
lOK = true;
}
//---------------------------------------------------------------------------
void IdMsg::SetSrv(String cS, int nP) //#D:101025
{
if (cS.Length()>0) IdSMTP->Host = cS;
if (nP > 0) IdSMTP->Port = nP;
}
//---------------------------------------------------------------------------
void IdMsg::Destino(String cD)
{
if (IdMs->Recipients->Count == 0) {
TIdEMailAddressItem *dst = IdMs->Recipients->Add();
dst->Address = cD;
} else {
IdMs->Recipients->Items[0]->Address = cD;
}
}
//---------------------------------------------------------------------------
void IdMsg::AddDestino(String cD)
{
TIdEMailAddressItem *dst = IdMs->Recipients->Add();
dst->Address = cD;
}
//---------------------------------------------------------------------------
void IdMsg::Asunto(String cA)
{
IdMs->Subject = cA;
}
//---------------------------------------------------------------------------
void IdMsg::AttachF(String cF)
{
TIdAttachmentFile *atm = new TIdAttachmentFile(IdMs->MessageParts, cF);
// v2,3 --- IdMs->MessageParts->Add();
atm->FileName = ExtractFileName(cF);
atm->ContentType = GetMIMETypeFromFile(cF);
//atm->ContentID = ExtractFileName(cF);
atm->ContentID = "<ExtractFileName>ParentPart = nri;
if (TextStartsWith(atm->ContentType, "image/")) atm->ContentDisposition = "inline";
}
//---------------------------------------------------------------------------
void IdMsg::AddText(String cT)
{
IdMs->Body->Add(cT);
}
//---------------------------------------------------------------------------
void IdMsg::AddTList(TStrings *sl)
{
IdMs->Body->Assign(sl);
}
//---------------------------------------------------------------------------
void IdMsg::ClearText()
{
IdMs->Body->Clear();
}
//---------------------------------------------------------------------------
void IdMsg::IsHTML(TStrings *sl)
{
// 1 -------------------- 1ª version
//if (npt==0){
// npt = 1;
// txp = new TIdText(IdMs->MessageParts, 0);
// IdMs->MessageParts->Add();
// txp->ContentType = "text/plain"; // 1ª parte es plain text
//}
//txp = new TIdText(IdMs->MessageParts, sl);
//IdMs->MessageParts->Add();
//IdMs->ContentType = "multipart/mixed"; (prueba, en outlook queda adjunto)
//IdMs->ContentType = "multipart/related; type=\"text/html\"";
//txp->ContentType = "text/html";
//txp->Body->Assign(sl);
// 1 -------------------
// 2 ---------------- Bien en Outlook y mal en hotmail (igual q anterior)
//IdMs->ContentType = "multipart/related; type=\"text/html\"";
//IdMs->Body->Assign(sl);
//
//txp = new TIdText(IdMs->MessageParts, 0);
//txp->ContentType = "text/plain"; // 1ª parte es plain text
//txp->Body->Text = "";
//
//
//txp = new TIdText(IdMs->MessageParts, sl);
//txp->ContentType = "text/html";
// 2 ---------------------
// 3 ----------------
//txp = new TIdText(IdMs->MessageParts, 0);
//txp->ContentType = "text/plain"; // 1ª parte es plain text
//txp = new TIdText(IdMs->MessageParts, sl);
//txp->ContentType = "text/html";
//txp->ContentTransfer = "quoted-printeble";
//IdMs->ContentType = "multipart/related; type=\"text/html\""; //key outlook
// 3 ---------------------
// 4 ---------------------
IdMs->ContentType = "multipart/alternative"; //key outlook
txp = new TIdText(IdMs->MessageParts, 0);
txp->ContentType = "text/plain";
txp->ParentPart = -1;
TIdText *rlp= new TIdText(IdMs->MessageParts, 0);
rlp->ContentType = "multipart/related; type=\"text/html\"";
rlp->ParentPart = -1;
txp = new TIdText(IdMs->MessageParts, sl);
txp->ContentType = "text/html";
txp->ContentTransfer = "quoted-printeble";
txp->ParentPart = rlp->Index;
nri = rlp->Index; //private in my class
}
//---------------------------------------------------------------------------
void IdMsg::Urgente()
{
IdMs->Priority = mpHigh;
}
//---------------------------------------------------------------------------
bool IdMsg::Envia()
{
bool lr = false;
try {
IdSMTP->Connect();
try {
IdSMTP->Send(IdMs);
lr = true;
} catch (...) {
}
::Sleep(990);
IdSMTP->Disconnect();
} catch (...) {
}
return lr;
}
//---------------------------------------------------------------------------
// #endif
//---------------------------------------------------------------------------
// #ifdef MdMAPI
//---------------------------------------------------------------------------
// OUTLOOK
//---------------------------------------------------------------------------
MyMsg::MyMsg()
{
nE = 0;
hSession = NULL;
pMAPILogon = NULL;
pMAPILogoff = NULL;
pMAPISendMail = NULL;
hMAPILib = ::LoadLibrary("MAPI32.DLL");
if (hMAPILib) {
lLb = true;
pMAPILogon = (LPMAPILOGON) GetProcAddress (hMAPILib, "MAPILogon");
pMAPISendMail = (LPMAPISENDMAIL) GetProcAddress (hMAPILib, "MAPISendMail");
pMAPILogoff = (LPMAPILOGOFF) GetProcAddress (hMAPILib, "MAPILogoff");
if ((pMAPILogon) && (pMAPISendMail) && (pMAPILogoff)) {
lOK = true;
ZeroMemory(&RecipInfo, sizeof(MapiRecipDesc)); //todo a 0
RecipInfo.ulRecipClass = MAPI_TO;
ZeroMemory(&MapiMsg, sizeof(MapiMessage)); //todo a 0
ZeroMemory(&lpFiles, sizeof(MapiFileDesc));
}
}
}
MyMsg::~MyMsg()
{
if (lLb)
::FreeLibrary(hMAPILib);
}
void MyMsg::Destino(AnsiString cD)
{
RecipInfo.lpszName = cD.c_str();
RecipInfo.lpszAddress = ("SMTP:" + cD).c_str();
MapiMsg.lpOriginator = NULL; //&SenderInfo;
MapiMsg.nRecipCount = 1;
MapiMsg.lpRecips = &RecipInfo;
}
void MyMsg::Asunto(AnsiString cA)
{
MapiMsg.lpszSubject = cA.c_str();
}
void MyMsg::AttachF(AnsiString cF)
{
strcpy(aPathS, cF.c_str());
//strcpy(aFileS, ExtractFileName(cF).c_str());
lpFiles.ulReserved = 0;
lpFiles.lpszPathName = aPathS;
lpFiles.lpszFileName = NULL; //aFileS;
lpFiles.lpFileType = NULL; //".PDF";
lpFiles.nPosition = -1;
lpFiles.flFlags = 0;
MapiMsg.nFileCount = 1;
MapiMsg.lpFiles = &lpFiles;
}
void MyMsg::AddText(AnsiString cT)
{
cBdy += String(cT + "\r\n");
}
void MyMsg::ClearText()
{
MapiMsg.lpszNoteText = "";
cBdy = "";
}
void MyMsg::Urgente()
{
//MapiMsg.flFlags =
}
bool MyMsg::Envia()
{
MapiMsg.lpszNoteText = cBdy.c_str();
nE = pMAPILogon(0, NULL, NULL, MAPI_LOGON_UI, 0, &hSession);
if (nE == 0) {
nE = pMAPISendMail(hSession, 0, &MapiMsg, 0, 0);
pMAPILogoff(hSession, 0, 0, 0);
}
return (nE==SUCCESS_SUCCESS);
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void SendByOutLook(String cD, String cA, String cB, String cF)
{
Variant Outlook;
Variant MailItem;
try {
Outlook = GetActiveOleObject("Outlook.Application");
}
catch (...) {
Outlook = CreateOleObject("Outlook.Application");
}
MailItem = Outlook.OleFunction("CreateItem", 0);
MailItem.OlePropertyGet("Recipients").OleFunction("Add", cD.c_str());
MailItem.OlePropertySet("Subject", cA.c_str());
MailItem.OlePropertySet("Body", cB.c_str());
if (cF.Length()>0) {
MailItem.OlePropertyGet("Attachments").OleFunction("Add", cF.c_str());
}
MailItem.Exec(Procedure("Send"));
::Sleep(900);
Outlook = Unassigned;
}
//---------------------------------------------------------------------------
// #endif
//---------------------------------------------------------------------------
/*
void __fastcall TForm1::SendOut()
{
const int olMailItem = 0;
Variant Outlook;
Variant MailItem;
Variant dest;
Variant att;
try
{
Outlook = GetActiveOleObject("Outlook.Application") ;
}
catch (...)
{
Outlook = CreateOleObject("Outlook.Application") ;
}
MailItem = Outlook.OleFunction("CreateItem", olMailItem);
//MailItem.Recipients.Add("delphi.guide@about.com") ;
//MailItem.Exec(PropertyGet("Recipients")).Exec(OleFunction("Add", "delphi.guide@about.com"));
dest = MailItem.OlePropertyGet("Recipients");
dest.OleFunction("Add", "hzo.inf2@cotursahotels.com");
MailItem.OlePropertySet("Subject", "Subject: Outlook Mail From Delphi");
MailItem.OlePropertySet("Body", "Welcome to my homepage:http://delphi.about.com");
//MailItem.Attachments.Add("C:\Windows\Win.ini") ;
att = MailItem.OlePropertyGet("Attachments");
att.OleFunction("Add", "C:\\SiSSetup.txt");
//MailItem.Send;
MailItem.Exec(Procedure("Send"));
Outlook = Unassigned;
}
//----------------------------------------------------------------
void __fastcall TfInicial::MAPIMsg()
{
MyMsg Msg;
String cAs, cMs;
int nR;
if (opU->Checked)
cMs = opU->Caption + ". ";
if (Msg.lOK) {
cAs = cMs + MLG.TextLg("Msg de") + " " + tQu->Text +
", (" + lbFc->Caption + " " + lbHr->Caption + ")";
Msg.Destino(cDs);
Msg.Asunto(cAs);
if (opT->Checked)
cMs += "( " + opT->Caption + " )\r\n";
Msg.AddText(StringOfChar('-', 42));
Msg.AddText(MLG.TextLg("De") + ":\t" + tQu->Text);
Msg.AddText(MLG.TextLg("Empresa") + ":\t" + tEm->Text);
Msg.AddText(MLG.TextLg("Teléfono") + ":\t" + tTl->Text);
Msg.AddText(StringOfChar('-', 42));
Msg.AddText(MLG.TextLg("Mensaje") + ": " + cMs);
Msg.AddText(tMs->Text);
Msg.AddText(StringOfChar('-', 42));
Msg.AddText(MLG.TextLg("Enviado por") + ": " + tEp->Text);
Msg.AddText("[" + lbFc->Caption + " " + lbHr->Caption +
", " + NameOfPC() + "]");
if (Msg.Envia()) {
SBox("Mensaje en salida para " + xTo->Text, 2);
Close();
}
else
SBox("Error MAPI: " + IntToStr(Msg.nE), 1);
}
else
SBox("Error inicializando MAPI", 1);
}
//---------------------------------------------------------------------------
int __fastcall TfInicial::SendMsgMAPI(String cDs, String cAs, String cTx)
{
MapiMessage MapiMsg;
MapiRecipDesc RecipInfo;
LPMAPILOGON pMAPILogon = NULL;
LPMAPILOGOFF pMAPILogoff = NULL;
LPMAPISENDMAIL pMAPISendMail = NULL;
LHANDLE hSession = NULL;
int nE;
HINSTANCE hMAPILib = ::LoadLibrary("MAPI32.DLL");
if (!hMAPILib) return 1;
pMAPILogon = (LPMAPILOGON) GetProcAddress (hMAPILib, "MAPILogon");
pMAPISendMail = (LPMAPISENDMAIL) GetProcAddress (hMAPILib, "MAPISendMail");
pMAPILogoff = (LPMAPILOGOFF) GetProcAddress (hMAPILib, "MAPILogoff");
if (!(pMAPILogon) || !(pMAPISendMail) ||!(pMAPILogoff))
nE = 2;
else {
ZeroMemory(&RecipInfo, sizeof(MapiRecipDesc)); //todo a 0
RecipInfo.ulRecipClass = MAPI_TO;
RecipInfo.lpszName = cDs.c_str();
RecipInfo.lpszAddress = ("SMTP:" + cDs).c_str();
ZeroMemory(&MapiMsg, sizeof(MapiMessage)); //todo a 0
MapiMsg.lpszSubject = cAs.c_str();
MapiMsg.lpszNoteText = cTx.c_str();
MapiMsg.lpOriginator = NULL; //&SenderInfo;
MapiMsg.nRecipCount = 1;
MapiMsg.lpRecips = &RecipInfo;
nE = pMAPILogon(0, NULL, NULL, MAPI_LOGON_UI, 0, &hSession);
if (nE == 0) {
nE = pMAPISendMail(hSession, 0, &MapiMsg, 0, 0);
pMAPILogoff(hSession, 0, 0, 0);
}
}
::FreeLibrary(hMAPILib);
return nE;
}
//---------------------------------------------------------------------------
*/
|
|
|
| Volver arriba |
|
 |
Touchsoftwares Master


Registrado: 16 Dic 2002Mensajes: 869Ubicación: MEXICO Playa del Carmen
|
Publicado: Dom 24 Abr, 2011 5:43 pm Asunto: Gracias |
|
|
Gracias por sus amables respuestas, no les habia contestado por que me dio varicela y estuve 20 dias fuera de circulacion. _________________ Ing. Gabriel Góngora Navarrete
TouchSoftwares Inc
http://www.touchsoftwares.com |
|
| Volver arriba |
|
 |
|
|
No puedes publicar temas nuevos en este foro No puedes responder a temas en este foro No puedes editar tus mensajes en este foro No puedes borrar tus mensajes en este foro No puedes votar en las encuestas de este foro
|
© 2002–2026 Club Builder · Funciona con phpBB.
|