rjiovanni
  • rjiovanni
  • 56% (Neutral)
  • Newbie Topic Starter
13 years ago
Hi, i am using VB6+eagetmail+Access2002 to download e-mails, but i dont want to use EML files to read then everytime.
How can i save my emails and retrieve it from my 'database'? What about the attachments?

thanks.
ivan
  • ivan
  • 100% (Exalted)
  • Administration
13 years ago

Hi, i am using VB6+eagetmail+Access2002 to download e-mails, but i dont want to use EML files to read then everytime.
How can i save my emails and retrieve it from my 'database'? What about the attachments?

thanks.

rjiovanni wrote:



Hi, you can save Mail.Content (binary array) to access database as OLE object data type.

Then when you want to read it, please read the binary data from access and use

Mail.Load method to load it back to Mail object.

With above methods, Attachments will be saved/loaded as well.
rjiovanni
  • rjiovanni
  • 56% (Neutral)
  • Newbie Topic Starter
13 years ago
Ohhh, thnks for the tip ... i will try it.
rjiovanni
  • rjiovanni
  • 56% (Neutral)
  • Newbie Topic Starter
13 years ago
Okay, i saved the binary as you say without problems, but i cant retrieve it, check my code please:

Saving binary:

...
rs!email = oMail.Content 'email field = data type OLE Object on Access2002
...

Open binary

oMail.Load rs!email

i got that error:

-2147024809: NativeErrorCode: 87[DATA]

What i am doing wrong here?

Thanks.
ivan
  • ivan
  • 100% (Exalted)
  • Administration
13 years ago

Okay, i saved the binary as you say without problems, but i cant retrieve it, check my code please:

Saving binary:

...
rs!email = oMail.Content 'email field = data type OLE Object on Access2002
...

Open binary

oMail.Load rs!email

i got that error:

-2147024809: NativeErrorCode: 87[DATA]

What i am doing wrong here?

Thanks.

rjiovanni wrote:



Hi, you should use AppendChunk and GetChunk method to access the binary data.

Please tell me what database object you used? DAO or ADO.
Then I will give you the example code.
ivan
  • ivan
  • 100% (Exalted)
  • Administration
13 years ago

Okay, i saved the binary as you say without problems, but i cant retrieve it, check my code please:

Saving binary:

...
rs!email = oMail.Content 'email field = data type OLE Object on Access2002
...

Open binary

oMail.Load rs!email

i got that error:

-2147024809: NativeErrorCode: 87[DATA]

What i am doing wrong here?

Thanks.

rjiovanni wrote:



Here is a DAO example:

mail_data = oMail.Content

rs!email_size = LenB( mail_data ) 'please add a number field in your table to store the binary data size.
rs!email = mail_data

then when you load it back, please use the following code:

mail_len = rs!email_size
mail_data = rs!email.GetChunk(0, mail_len)
oMail.Load mail_data
rjiovanni
  • rjiovanni
  • 56% (Neutral)
  • Newbie Topic Starter
13 years ago
I am using ADO ...
ivan
  • ivan
  • 100% (Exalted)
  • Administration
13 years ago

I am using ADO ...

rjiovanni wrote:




Here is a DAO example:

mail_data = oMail.Content

rs!email_size = LenB( mail_data ) 'please add a number field in your table to store the binary data size.
rs!email = mail_data

then when you load it back, please use the following code:

mail_len = rs!email_size
mail_data = rs!email.GetChunk(0, mail_len)
oMail.Load mail_data
rjiovanni
  • rjiovanni
  • 56% (Neutral)
  • Newbie Topic Starter
13 years ago
Perfect m8, thanks for the tip, i neve work before with binary, never had to. ehehehhe
rjiovanni
  • rjiovanni
  • 56% (Neutral)
  • Newbie Topic Starter
13 years ago
Can i send the same e-mail using his "content" field?

Or i must create a temp eml file to send an e-mail?

I did a sample using the eml file do load the email to the object and send it, but i had a problem with the subject property, didn´t work with the "new subject", i change the original one.

Great component.
ivan
  • ivan
  • 100% (Exalted)
  • Administration
13 years ago

Can i send the same e-mail using his "content" field?

Or i must create a temp eml file to send an e-mail?

I did a sample using the eml file do load the email to the object and send it, but i had a problem with the subject property, didn´t work with the "new subject", i change the original one.

Great component.

rjiovanni wrote:



Are you using EASendMail to send email? could you show me your code?

rjiovanni
  • rjiovanni
  • 56% (Neutral)
  • Newbie Topic Starter
13 years ago

    'zera atributos
    m_oSmtp.Reset  'because m_oSmtp is a member variahle, so we need to clear the the property
    m_oSmtp.Asynchronous = 1
    m_oSmtp.ServerAddr = ""
    m_oSmtp.ServerPort = 25
    m_oSmtp.SSL_uninit
    m_oSmtp.UserName = ""
    m_oSmtp.Password = ""
    
    m_oSmtp.ServerAddr = sServidor_SMTP
    m_oSmtp.Protocol = rs!protocolo_envio
    
    If sServidor_SMTP <> "" Then
        If rs!autenticacao_requerida Then
            m_oSmtp.UserName = rs!usuario
            m_oSmtp.Password = rs!senha
        End If
        
        If rs!autenticacao_ssl Then
            If m_oSmtp.SSL_init() <> 0 Then
                MsgBox ("Falha ao carregar a biblioteca SSL!")  'failed to load SSL library
                Exit Function
            End If
            'If SSL port is 465 or other port rather than 25 port, please use
            'm_oSmtp.ServerPort = 465
            'm_oSmtp.SSL_starttls = 0
        End If
    End If
    
    m_oSmtp.Charset = rs!encoding 'm_arCharset(24, 1)
    Dim name, addr As String
    fnParseAddr psEmailDe, name, addr
    
    'Using this email to be replied to another address
    'm_oSmtp.ReplyTo = ReplyAddress
    
    m_oSmtp.From = name
    m_oSmtp.FromAddr = addr
    
    'add digital signature
    m_oSmtp.SignerCert.Unload
    
    If rs!assinatura_digital Then
        If Not m_oSmtp.SignerCert.FindSubject(addr, CERT_SYSTEM_STORE_CURRENT_USER, "my") Then
            MsgBox m_oSmtp.SignerCert.GetLastError() & ":" & addr
'            btnSend.Enabled = True
            btnCancel.Enabled = False
        Exit Function
        End If
        If Not m_oSmtp.SignerCert.HasPrivateKey Then
            MsgBox "O certificado não possui chave privada, portanto não poderá ser usado na assinatura deste E-mail!" '"Signer certificate has not private key, this certificate can not be used to sign email!"
'            btnSend.Enabled = True
            btnCancel.Enabled = False
            Exit Function
        End If
    End If
    
    m_oSmtp.AddRecipientEx psEmailPara, 0  ' 0, Normal recipient, 1, cc, 2, bcc
    m_oSmtp.AddRecipientEx sEndereco_cc, 0
    
    Dim recipients As String
    recipients = psEmailPara & "," & sEndereco_cc
    fnTrim recipients, ","
    
    Dim i, Count As Integer
    'encrypt email by recipients certificate
    m_oSmtp.RecipientsCerts.Clear
    If rs!criptografar Then
        Dim arAddr
        arAddr = SplitEx(recipients, ",")   'split the multiple address to an array
        Count = UBound(arAddr)
        For i = LBound(arAddr) To Count
            addr = arAddr(i)
            fnTrim addr, " ,;"
            If addr <> "" Then
                'find the encrypting certificate for every recipients
                Dim oEncryptCert As New EASendMailObjLib.Certificate
                If Not oEncryptCert.FindSubject(addr, CERT_SYSTEM_STORE_CURRENT_USER, "AddressBook") Then
                    If Not oEncryptCert.FindSubject(addr, CERT_SYSTEM_STORE_CURRENT_USER, "my") Then
                        MsgBox oEncryptCert.GetLastError() & ":" & addr
'                        btnSend.Enabled = True
                        btnCancel.Enabled = False
                        Exit Function
                    End If
                End If
                m_oSmtp.RecipientsCerts.Add oEncryptCert
            End If
        Next
    End If
    
    Count = UBound(m_arAttachment)
    For i = 0 To Count - 1
        If m_oSmtp.AddAttachment(m_arAttachment(i)) <> 0 Then
            MsgBox m_oSmtp.GetLastErrDescription() & ":" & m_arAttachment(i)
'            btnSend.Enabled = True
            btnCancel.Enabled = False
            Exit Function
        End If
    Next
    
    'Salva arquivo de email com base no database (EML e HTML)  <<<<<<<<<<<<<<<<<<<<<< SAVE EML and HTML File
    If Not eMail_Salvar_EML(pId_Email, sPath_Arq_EML, sPath_Arq_HTML) Then
        Atencao "Ocorreram erros na geração do arquivo EML! Verique as permissões da pasta " & pPathEmails
        Exit Function
    End If
    
    ' Load EML file to body text temporally  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< import Mail
    m_oSmtp.ImportMail sPath_Arq_EML
    ' Assign Eml file data to raw content  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< load raw_Content
    m_oSmtp.raw_Content = m_oSmtp.BodyText
    
    m_oSmtp.BodyFormat = 1    ' Using HTML FORMAT to send mail
    
    m_oSmtp.Subject = psAssunto  '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW SUBJECT 
    
    'm_oSmtp.
    
    If InStr(1, recipients, ",", 1) > 1 And sServidor_SMTP = "" Then
        'To send email without specified smtp server, we have to send the emails one by one
        ' to multiple recipients. That is because every recipient has different smtp server.
        DirectSend m_oSmtp, recipients
        
        btnCancel.Enabled = False
        textStatus.SimpleText = ""
        Exit Function
    End If
    
    textStatus.SimpleText = "Conectando " & sServidor_SMTP & " ..."
    m_bIdle = False
    m_bCancel = False
    m_bError = False
    pgBar.Value = 0
    
    m_oSmtp.SendMail
    
    'wait the asynchronous call finish.
    Do While Not m_bIdle
        DoEvents
    Loop
ivan
  • ivan
  • 100% (Exalted)
  • Administration
13 years ago


    'zera atributos
    m_oSmtp.Reset  'because m_oSmtp is a member variahle, so we need to clear the the property
    m_oSmtp.Asynchronous = 1
    m_oSmtp.ServerAddr = ""
    m_oSmtp.ServerPort = 25
    m_oSmtp.SSL_uninit
    m_oSmtp.UserName = ""
    m_oSmtp.Password = ""
    
    m_oSmtp.ServerAddr = sServidor_SMTP
    m_oSmtp.Protocol = rs!protocolo_envio
    
    If sServidor_SMTP <> "" Then
        If rs!autenticacao_requerida Then
            m_oSmtp.UserName = rs!usuario
            m_oSmtp.Password = rs!senha
        End If
        
        If rs!autenticacao_ssl Then
            If m_oSmtp.SSL_init() <> 0 Then
                MsgBox ("Falha ao carregar a biblioteca SSL!")  'failed to load SSL library
                Exit Function
            End If
            'If SSL port is 465 or other port rather than 25 port, please use
            'm_oSmtp.ServerPort = 465
            'm_oSmtp.SSL_starttls = 0
        End If
    End If
    
    m_oSmtp.Charset = rs!encoding 'm_arCharset(24, 1)
    Dim name, addr As String
    fnParseAddr psEmailDe, name, addr
    
    'Using this email to be replied to another address
    'm_oSmtp.ReplyTo = ReplyAddress
    
    m_oSmtp.From = name
    m_oSmtp.FromAddr = addr
    
    'add digital signature
    m_oSmtp.SignerCert.Unload
    
    If rs!assinatura_digital Then
        If Not m_oSmtp.SignerCert.FindSubject(addr, CERT_SYSTEM_STORE_CURRENT_USER, "my") Then
            MsgBox m_oSmtp.SignerCert.GetLastError() & ":" & addr
'            btnSend.Enabled = True
            btnCancel.Enabled = False
        Exit Function
        End If
        If Not m_oSmtp.SignerCert.HasPrivateKey Then
            MsgBox "O certificado não possui chave privada, portanto não poderá ser usado na assinatura deste E-mail!" '"Signer certificate has not private key, this certificate can not be used to sign email!"
'            btnSend.Enabled = True
            btnCancel.Enabled = False
            Exit Function
        End If
    End If
    
    m_oSmtp.AddRecipientEx psEmailPara, 0  ' 0, Normal recipient, 1, cc, 2, bcc
    m_oSmtp.AddRecipientEx sEndereco_cc, 0
    
    Dim recipients As String
    recipients = psEmailPara & "," & sEndereco_cc
    fnTrim recipients, ","
    
    Dim i, Count As Integer
    'encrypt email by recipients certificate
    m_oSmtp.RecipientsCerts.Clear
    If rs!criptografar Then
        Dim arAddr
        arAddr = SplitEx(recipients, ",")   'split the multiple address to an array
        Count = UBound(arAddr)
        For i = LBound(arAddr) To Count
            addr = arAddr(i)
            fnTrim addr, " ,;"
            If addr <> "" Then
                'find the encrypting certificate for every recipients
                Dim oEncryptCert As New EASendMailObjLib.Certificate
                If Not oEncryptCert.FindSubject(addr, CERT_SYSTEM_STORE_CURRENT_USER, "AddressBook") Then
                    If Not oEncryptCert.FindSubject(addr, CERT_SYSTEM_STORE_CURRENT_USER, "my") Then
                        MsgBox oEncryptCert.GetLastError() & ":" & addr
'                        btnSend.Enabled = True
                        btnCancel.Enabled = False
                        Exit Function
                    End If
                End If
                m_oSmtp.RecipientsCerts.Add oEncryptCert
            End If
        Next
    End If
    
    Count = UBound(m_arAttachment)
    For i = 0 To Count - 1
        If m_oSmtp.AddAttachment(m_arAttachment(i)) <> 0 Then
            MsgBox m_oSmtp.GetLastErrDescription() & ":" & m_arAttachment(i)
'            btnSend.Enabled = True
            btnCancel.Enabled = False
            Exit Function
        End If
    Next
    
    'Salva arquivo de email com base no database (EML e HTML)  <<<<<<<<<<<<<<<<<<<<<< SAVE EML and HTML File
    If Not eMail_Salvar_EML(pId_Email, sPath_Arq_EML, sPath_Arq_HTML) Then
        Atencao "Ocorreram erros na geração do arquivo EML! Verique as permissões da pasta " & pPathEmails
        Exit Function
    End If
    
    ' Load EML file to body text temporally  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< import Mail
    m_oSmtp.ImportMail sPath_Arq_EML
    ' Assign Eml file data to raw content  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< load raw_Content
    m_oSmtp.raw_Content = m_oSmtp.BodyText
    
    m_oSmtp.BodyFormat = 1    ' Using HTML FORMAT to send mail
    
    m_oSmtp.Subject = psAssunto  '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW SUBJECT 
    
    'm_oSmtp.
    
    If InStr(1, recipients, ",", 1) > 1 And sServidor_SMTP = "" Then
        'To send email without specified smtp server, we have to send the emails one by one
        ' to multiple recipients. That is because every recipient has different smtp server.
        DirectSend m_oSmtp, recipients
        
        btnCancel.Enabled = False
        textStatus.SimpleText = ""
        Exit Function
    End If
    
    textStatus.SimpleText = "Conectando " & sServidor_SMTP & " ..."
    m_bIdle = False
    m_bCancel = False
    m_bError = False
    pgBar.Value = 0
    
    m_oSmtp.SendMail
    
    'wait the asynchronous call finish.
    Do While Not m_bIdle
        DoEvents
    Loop

rjiovanni wrote:




Hi, if you want to edit the subject, then you should not use raw_Content property.

you should use LoadMessage method
from:
' Load EML file to body text temporally <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< import Mail
m_oSmtp.ImportMail sPath_Arq_EML
' Assign Eml file data to raw content <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< load raw_Content
m_oSmtp.raw_Content = m_oSmtp.BodyText

m_oSmtp.BodyFormat = 1 ' Using HTML FORMAT to send mail

change it to:

' Load EML file to body text temporally <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< import Mail
m_oSmtp.LoadMessage sPath_Arq_EML

m_oSmtp.BodyFormat = 1
rjiovanni
  • rjiovanni
  • 56% (Neutral)
  • Newbie Topic Starter
13 years ago
I got this error now:

UserPostedImage


    m_oSmtp.LoadMessage sPath_Arq_EML


    ' Load EML file to body text temporally
    ' m_oSmtp.ImportMail sPath_Arq_EML
    ' Assign Eml file data to raw content
    ' m_oSmtp.raw_Content = m_oSmtp.BodyText
    
    m_oSmtp.BodyFormat = 1    ' Using HTML FORMAT to send mail
    
    m_oSmtp.Subject = psAssunto
    

When i uncomment the old lines, the email will be send ok, except for the subject...
ivan
  • ivan
  • 100% (Exalted)
  • Administration
13 years ago


When i uncomment the old lines, the email will be send ok, except for the subject...

rjiovanni wrote:



with raw_Content, you cannot edit anything of the email.

please generate a log file with LoadMessage and raw_Content and send it to support@emailarchitect.net so that I can have a check.

m_oSmtp.Subject = psAssunto
m_oSmtp.LogFileName = "d:\smtp.txt"

EXPLORE TUTORIALS

© All Rights Reserved, AIFEI Software Limited & AdminSystem Software Limited.