Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

spedire Email da access con smtp.gmail.com

1,778 views
Skip to first unread message

sani...@gmail.com

unread,
Oct 21, 2016, 6:37:35 PM10/21/16
to
Sto cercando un codice che mi permetta di inviare le email direttamente dal software che sto realizzando. Cercando sul web ho trovato questo che segue, ma google blocca le app non sicure. Allora ho provato dando accesso alle app non sicure ma il problema è lo stesso, mi da come messaggio: l'errore 0x80040217

Potreste aiutarmi a risolvere l'enigma? grazie in anticipo!

Qui il codice:

Dim mail As New Message
Dim config As Configuration
Dim strMailTo As String, strSubject As String, strHtmlBody As String
Set config = mail.Configuration

config(cdoSendUsingMethod) = cdoSendUsingPort
config(cdoSMTPServer) = "smtp.gmail.com"
config(cdoSMTPServerPort) = 25
config(cdoSMTPAuthenticate) = cdoBasic
config(cdoSMTPUseSSL) = True
config(cdoSendUserName) = "mioac...@gmail.com"
config(cdoSendPassword) = "miapasswordgmail"
config.Fields.Update

mail.To = "indi...@email.it"
mail.From = config(cdoSendUserName)
mail.Subject = "Subject from VBA"
mail.HTMLBody = "<b>Body from VBA<b/>"

'mail.AddAttachment = "scrivere link"

On Error Resume Next
mail.Send

If Err.Number <> 0 Then
MsgBox Err.Description, vbCritical, "C'è stato un errore"
End If

rigoni

unread,
Oct 21, 2016, 9:26:15 PM10/21/16
to


ha scritto nel messaggio
news:8f416e27-cdde-40f2...@googlegroups.com...

<Sto cercando un codice che mi permetta di inviare le email direttamente dal
software che sto realizzando. Cercando sul web ho trovato questo che segue,
ma google blocca le app non sicure. Allora ho <provato dando accesso alle
app non sicure ma il problema è lo stesso, mi da come messaggio: l'errore
0x80040217

con il tuo codice , ricevevo esattamente lo stesso errore.
Allora sono andato sul mio account gmail, ho impostato a ON la possibilità
di usare app meno sicure ( era OFF ) , sono uscito dall'account.

Ho riprovato e non ricevo più l'errore e le mail arrivano al destinatario
( un account virgilio.it ).

Uso access 2007

ciao

sani...@gmail.com

unread,
Oct 22, 2016, 9:11:55 AM10/22/16
to
Il giorno sabato 22 ottobre 2016 03:26:15 UTC+2, rigoni ha scritto:
> ha scritto nel messaggio
> news:8f416e27-cdde-40f2...@googlegroups.com...
>
> Allora sono andato sul mio account gmail, ho impostato a ON la possibilità
> di usare app meno sicure ( era OFF ) , sono uscito dall'account.

Adesso funziona.
Ieri avevo impostato su On, ma non ero uscito dall'account. evidentemente era questo il problema. Grazie il tuo feedback mi ha aiutato a capire come risolvere il problema :)

Bruno Campanini

unread,
Oct 22, 2016, 1:49:27 PM10/22/16
to
rigoni submitted this idea :

> con il tuo codice , ricevevo esattamente lo stesso errore.
> Allora sono andato sul mio account gmail, ho impostato a ON la possibilità di
> usare app meno sicure
Dove, dove, dove?

> ( era OFF ) , sono uscito dall'account.

Bruno

sani...@gmail.com

unread,
Oct 23, 2016, 6:42:01 PM10/23/16
to
> Dove, dove, dove?

Ciao Bruno, dopo esserti loggato su gmail, in altro a destra dovresti vedere l'icona con la tua foto dell'account.
- clicca su foto account
- poi clicca su una "account personale"
- poi clicca su "accesso e sicurezza"
- poi clicca sulla barra di sinistra alla voce "app e siti collegati"
- in fine scorri in basso fino alla voce desiderata "Consenti app meno sicure"



sani...@gmail.com

unread,
Oct 23, 2016, 6:46:05 PM10/23/16
to
Scusate ancora una richiesta.
Per inviare l'email da vba ho attivato: Microsoft CDO for windows 2000 library
e funziona tutto. Ma se devo inviare più allegati come devo gestire il codice?

al momento la parte finale del codice che ho scritto è così:

'INVIO EMAIL
Mail.BCC = mailBBC
Mail.From = Config(cdoSendUserName)
Mail.Subject = Me.MailSubjact
Mail.HTMLBody = Me.MailBody

If Not IsNull(Me.MailAttach) Then Mail.AddAttachment (Me.MailAttach)

Mail.Send
MsgBox "Sent"



Grzie in anticipo

Bruno Campanini

unread,
Oct 23, 2016, 6:59:31 PM10/23/16
to
sani...@gmail.com brought next idea :
Quella proprietà era già settata ON... e il tuo CDO
qui da me continua a non funzionare.
Né con gmail né con infinito.
Non ho provato con altri provider perché non mi interessa tanto,
era solo una curiosità giacché quel CDO non sono mai riuscito
a farlo funzionare.

Comunque ti rigrazio dell'informazione.
Bruno

Bruno Campanini

unread,
Oct 23, 2016, 7:17:01 PM10/23/16
to
sani...@gmail.com has brought this to us :
> Scusate ancora una richiesta.
> Per inviare l'email da vba ho attivato: Microsoft CDO for windows 2000
> library e funziona tutto. Ma se devo inviare più allegati come devo gestire
> il codice?
Non so come debba essere gestito con CDO.
Con Access/Outlook, Attachments è una Collection che si carica
con un For...Next poi con l'oggetto posta (tipo eMail.Attachments)
si invia con Send assieme a tutto il resto.


> al momento la parte finale del codice che ho scritto è così:
>
> 'INVIO EMAIL
> Mail.BCC = mailBBC
> Mail.From = Config(cdoSendUserName)
> Mail.Subject = Me.MailSubjact
> Mail.HTMLBody = Me.MailBody
>
> If Not IsNull(Me.MailAttach) Then Mail.AddAttachment (Me.MailAttach)
Per analogia a quanto detto sopra, prova così:

For i = 1 To 3
arrAttach(1) = C:\File1.txt
arrAttach(2) = C:\File2.txt
arrAttach(3) = C:\File3.txt
Next
Mail.Attachment.AddAttachment arrAttach

Bruno

siga...@gmail.com

unread,
Oct 24, 2016, 3:29:34 PM10/24/16
to
> Per analogia a quanto detto sopra, prova così:
>
> For i = 1 To 3
> arrAttach(1) = C:\File1.txt
> arrAttach(2) = C:\File2.txt
> arrAttach(3) = C:\File3.txt
> Next
> Mail.Attachment.AddAttachment arrAttach

Purtroppo non funziona!

rigoni

unread,
Oct 24, 2016, 4:58:50 PM10/24/16
to


<<ha scritto nel messaggio
news:9ee3aaa0-347d-4632...@googlegroups.com...
<<Purtroppo non funziona!


Dim AttachmentPath(3) As Variant
AttachmentPath(1) = "C:\temp\uno.txt"
AttachmentPath(2) = "C:\temp\due.txt"
AttachmentPath(3) = "C:\temp\tre.txt"

For i = LBound(AttachmentPath) To UBound(AttachmentPath)
If AttachmentPath(i) <> "" And AttachmentPath(i) <> "False"
Then
mail.AddAttachment AttachmentPath(i)
End If
Next i

sani...@gmail.com

unread,
Oct 24, 2016, 6:29:55 PM10/24/16
to
Grazie a entrambi che mi avete accompagnato in questa ricerca di codice, sia a Rigoni che a Bruno il quale mi ha dato l'idea dell'array, perché in questo modo anziché avere un solo campo ho pensato di mettere 5 campi per ognuno del quale assegnare un possibile link (l'allegato) e con questo codice ho risolto:

If Not IsNull(Me.MailAttach0) Then Mail.AddAttachment (Me.MailAttach0)
If Not IsNull(Me.MailAttach1) Then Mail.AddAttachment (Me.MailAttach1)
If Not IsNull(Me.MailAttach2) Then Mail.AddAttachment (Me.MailAttach2)
If Not IsNull(Me.MailAttach3) Then Mail.AddAttachment (Me.MailAttach3)
If Not IsNull(Me.MailAttach4) Then Mail.AddAttachment (Me.MailAttach4)

Bruno Campanini

unread,
Oct 24, 2016, 8:09:21 PM10/24/16
to
sani...@gmail.com presented the following explanation :
Beh vuoi proprio che non accetti un array come parametro?
Fa' un ultimo esperimento ... che sono curioso!
Sostituisci le tue cinque righe con:

For i = 0 to 4
If Not IsNull(Me("MailAttach" & i))
Then Mail.AddAttachment Me("MailAttach" & i)
End If
Next

In ogni caso, mi manderesti il listato completo della procedura
funzionante?
Mi sembra impossibile che qui da me non debba funzionare.
Io ho un account gmail tipo IMAP con:

Incoming mail server = imap.gmail.com porta 993, SSL
Outgoing server = smtp.gmail.com porta 587, TLS

Molte grazie
Bruno

sani...@gmail.com

unread,
Oct 25, 2016, 7:09:40 PM10/25/16
to
> In ogni caso, mi manderesti il listato completo della procedura
> funzionante?
> Mi sembra impossibile che qui da me non debba funzionare.
> Io ho un account gmail tipo IMAP con:
>
> Incoming mail server = imap.gmail.com porta 993, SSL
> Outgoing server = smtp.gmail.com porta 587, TLS
>
> Molte grazie
> Bruno

Tu non ci crederai ma dopo aver funzionato e mandato e ricevuto email, da ieri sera lo stesso identico codice su gmail non funziona più per tali ragioni ho fatto un account con outlook.it e per il momento va!.... che dire ... cose turche!!!

Private Sub cmdSENDmail_Click()
'Richiede attivazione Microsoft CDO for windows 2000 library

Dim RST As Recordset, filtRST As Recordset
Dim sqlRST As String

Dim Mail As New Message
Dim Config As Configuration: Set Config = Mail.Configuration
Dim mailBBC As String
Dim minCNT As Integer, maxCNT As Integer
Dim MailAttach As String

If IsNull(Me.CRN) Then
MsgBox "SELEZIONARE UNA CATEGORIA!", vbInformation
Exit Sub
End If

'DEFINIZIONE DEL RECORDSET
sqlRST = "stringa sql"
Set RST = CurrentDb.OpenRecordset(sqlRST)
RST.Filter = "stringa filtro sql"
Set filtRST = RST.OpenRecordset()

'CONTEGGIO DEL RECORDSET
filtRST.MoveLast
maxCNT = filtRST.RecordCount
filtRST.MoveFirst

'CONFIGURAZIONE DELL'EMAIL
Config(cdoSendUsingMethod) = cdoSendUsingPort
Config(cdoSMTPServer) = "smtp-mail.outlook.com"
Config(cdoSMTPServerPort) = 25
Config(cdoSMTPAuthenticate) = cdoBasic
Config(cdoSMTPUseSSL) = True
Config(cdoSendUserName) = "Mia...@outlook.it"
Config(cdoSendPassword) = "MiaPassword"
Config.Fields.Update

'CICLO PER POPOLARE LA VOCE EMAIL
Do Until maxCNT = minCNT
minCNT = minCNT + 1
If maxCNT = minCNT Then
mailBBC = mailBBC & filtRST.Fields("EMAIL")
Else
mailBBC = mailBBC & filtRST.Fields("EMAIL") & ","
End If

If minCNT < maxCNT Then filtRST.MoveNext
Loop



'INVIO EMAIL
Mail.BCC = mailBBC
Mail.From = Config(cdoSendUserName)
Mail.Subject = Me.MailSubjact
Mail.HTMLBody = Me.MailBody




If Not IsNull(Me.MailAttach0) Then Mail.AddAttachment (Me.MailAttach0)
If Not IsNull(Me.MailAttach1) Then Mail.AddAttachment (Me.MailAttach1)
If Not IsNull(Me.MailAttach2) Then Mail.AddAttachment (Me.MailAttach2)
If Not IsNull(Me.MailAttach3) Then Mail.AddAttachment (Me.MailAttach3)
If Not IsNull(Me.MailAttach4) Then Mail.AddAttachment (Me.MailAttach4)

Mail.Send
MsgBox "Sent"
End Sub

Fammi sapere se va ;)

Bruno Campanini

unread,
Oct 25, 2016, 8:38:56 PM10/25/16
to
sani...@gmail.com presented the following explanation :

> Fammi sapere se va ;)

No, non c'è niente da fare.

Ciao
Bruno
0 new messages