0

クライアントの mailto 電子メール アドレスと、電子メールに同封された請求書に到達するためのパスを含む Excel 範囲があります。

私のコードは、(私のGmailアカウントから)各mailtoアドレスに(請求書付きの)電子メールを送信することで構成されています。

添付ファイルを含めなくても、Automation エラーが発生します。なんで?

Sub SendMail()

Dim oCdo As Object
Dim oConf As Object
Dim Flds As Object
Dim strHtml As String  'variable contenu du corps de message
Dim destinataire As String
Dim attachment As String
Dim DerLig

' Définit le contenu du message au format HTML
strHtml = "<HTML><HEAD><BODY>"
strHtml = strHtml & "<center><b> Ceci est un message de test au format <i><Font Color=#ff0000 > HTML. </Font></i></b></center>"
strHtml = strHtml & "</br>Veuillez prendre connaissance de la piece jointe."
strHtml = strHtml & "</BODY></HEAD></HTML>"

DerLig = Range("A" & Rows.Count).End(xlUp).Row
For n = 1 To DerLig
n = n + 1
destinataire = Cells(n, 3).Value
attachement = Cells(n, 8).Value

Set oCdo = CreateObject("cdo.Message")
'Set oConf = CreateObject("cdo.configuration")
'Set Flds = oConf.Fields

With oCdo.configuration.Fields
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" 'adresse du serveur smtp
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 'tester 25, 465 ou 587
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True  'Utilise une connection SSL (True or False)
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 40
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 '0 : pas d'authentification, 1 : authentification basique
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "MY GMAIL" 'identifiant de messagerie
    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "MY PASSWORD" 'mot de passe de messagerie
    .Update
End With

With oCdo
    .Subject = "Votre facture"                                            ' objet du message
    .From = "MY GMAIL"                                                   ' adresse de l'expéditeur
    .To = destinataire                                                    ' adresse du destinataire
    .BCC = ""                                                             ' en copie cachée pour conserver trace
    .HtmlBody = strHtml                                                   ' corps du message HTML
    '.AddAttachment (attachement)                                         ' ajout de pièce jointe
    .MDNrequested = True
    .Send

End With

Set oCdo = Nothing

Next n

End Sub
4

1 に答える 1

0

それは次の行によるものです: .MDNrequested = True

false または欠落に設定されている場合、機能します。

私も同じ問題を抱えてる。MDN を「True」に設定すると、最初の .send の後に Excel が再起動します。電子メールは引き続き送信され、「受信フィードバック」の送信を求められます。

ブラジル

于 2013-08-07T17:06:48.087 に答える