email

Status
Niet open voor verdere reacties.

bonnowagt

Gebruiker
Lid geworden
7 dec 2006
Berichten
445
Ik heb een database van waaruit ik automatisch een mailtje kan versturen. Ik heb als host/provider: mailhost.hetnet.nl.

Ik o.a.verzend als volgt:
Code:
  objemail.To = TextBox2.Text
            objemail.Subject = TextBox3.Text
            objemail.Textbody = TextBox4.Text
            objemail.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            objemail.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
            "mailhost.hetnet.nl"
            objemail.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
            objemail.Configuration.Fields.Update()
            objemail.AddAttachment(TextBox5.Text)
            objemail.Send()
            If ComboBox1.Text = "hoge prioriteit" Then MSG.Priority = MailPriority.High
            If ComboBox1.Text = "normale prioriteit" Then MSG.Priority = MailPriority.Normal
            If ComboBox1.Text = "lage prioriteit" Then MSG.Priority = MailPriority.Low
            xx = MailPriority.High
            Dim SMTP As New SmtpClient()
            SMTP.UseDefaultCredentials = True
            SMTP.Port = 25
            status.Text = "Bericht is verzonden met " + ComboBox1.Text + " op " + Now()
            PictureBox1.Image = My.Resources.Good_mark

Het programma werkt prima, maar ik wil dus graag dat de gebruiker zijn eigen provider kan invoeren. Ik heb hiervoor een textbestand dat word ingeladen.

Heb dus nu:
Code:
 ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
            "mailhost.hetnet.nl"

textbox4.text wordt ingeladen. in het textbestandje staat: mailhost.hetnet.nl
dus textbox4.text wordt: mailhost.hetnet.nl

de code dus aangepast als volgt:
Code:
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
           textbox4.text

In textbox4.text verschijnt nu ook keurig: mailhost.hetnet.nl
Echter het zenden mislukt. Wat is hier verkeerd aan met mijn gedachtengang.
 
Volgens mij moeten er geen haakjes om, maar ik heb dit ook geprobeerd.
"maar dit werkt ook niet. Textbox4.text haalt gewoon wel de host vanaf het textbextandje. In mijn programma heb ik textbox4. nog op visible en zie dat het ook gewoon goed in de textbox word ingeladen, dus hij zou het moeten doen en toch lukt transport naar de provider niet
 
In textbox4.text verschijnt nu ook keurig: mailhost.hetnet.nl
Echter het zenden mislukt. Wat is hier verkeerd aan met mijn gedachtengang.

Het verzenden zal waarschijnlijk mis gaan omdat de betreffende provider niet toestaat dat zijn SMTP server wordt gebruikt via een account van een andere provider.
(Relaying)
 
Nee dat heeft er niets mee te maken als ik

("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"mailhost.hetnet.nl"
doe werkt het prima

doe ik

("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
tekstbox4.text

dan werkt het niet, terwijl in de textbox gewoon dezelfde naam staat.
 
HI zo dus

("http://schemas.microsoft.com/cdo/configuration/smtpserver") & tekstbox4.text
 
Als ik nu het volgende doe:
Code:
  objemail.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            objemail.Configuration.Fields.Item _
           ("http://schemas.microsoft.com/cdo/configuration/smtpserver") & textbox4.text
          CODE]

komt er een blauwe streep onder textbox4.text met de melding end of statement verwacht
 
Even uit proberen bv

("http://schemas.microsoft.com/cdo/configuration/smtpserver") = & textbox4.text

Het kan zijn dat je in de textbox "mailhost.hetnet.nl" Met Haakjes dus
 
Ik heb diverse dingen uitgeprobeerd maar eigenlijk ebgrijp ik niet dat het niet gewoon werkt. Niet met haakjes en niet zonder haakjes.

Wel werkt het bijvoorbeeld als ik het volgende doe:

textbox6="mailhost.hetnet.nl"
objemail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = TextBox4.Text

Het zou dan toch ook moeten werken als ik uit de provider.txt bestand de naam haal en inlaad . Ik zie dan ook dat in de textbox de naam komt te staan.
 
Je zegt "het werkt niet" en "het verzenden mislukt" maar kun je ook de exacte foutmelding laten zien?
 
Bij deze het programma:
Code:
Private Sub mailverzenden_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox6.Text = My.Computer.FileSystem.ReadAllText("C:\contact direct\provider\provider.txt")
        PictureBox1.Visible = False
        TextBox2.Text = Form1.ListView1.SelectedItems.Item(0).SubItems(12).Text
        
    End Sub
    Private Sub VerzendenMetBijlageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VerzendenMetBijlageToolStripMenuItem.Click
        Dim objemail
        ' TextBox6.Text = My.Computer.FileSystem.ReadAllText("C:\contact direct\provider\provider.txt")
        PictureBox1.Visible = True
        Try
        
            objemail = CreateObject("CDO.Message")
            objemail.From = TextBox1.Text
            If TextBox1.Text = "" Then MsgBox("U moet bij afzender(van) een emailadres invoeren") : Exit Sub

            If TextBox2.Text = "" Then MsgBox("U moet bij geadresseerde(aan) een emailadres invoeren") : Exit Sub
            objemail.To = TextBox2.Text
            objemail.Subject = TextBox3.Text
            objemail.Textbody = TextBox4.Text
            objemail.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            objemail.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = TextBox6.Text

          
            objemail.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
            objemail.Configuration.Fields.Update()
            objemail.AddAttachment(TextBox5.Text)
            objemail.Send()
            If ComboBox1.Text = "hoge prioriteit" Then MSG.Priority = MailPriority.High
            If ComboBox1.Text = "normale prioriteit" Then MSG.Priority = MailPriority.Normal
            If ComboBox1.Text = "lage prioriteit" Then MSG.Priority = MailPriority.Low
            xx = MailPriority.High
            Dim SMTP As New SmtpClient()
            SMTP.UseDefaultCredentials = True
            SMTP.Port = 25
            status.Text = "Bericht is verzonden met " + ComboBox1.Text + " op " + Now()
            PictureBox1.Image = My.Resources.Good_mark
        Catch ex As Exception
            status.Text = "Fout, bericht is niet verzonden."
            PictureBox1.Image = My.Resources.wrong
            MsgBox(ex.Message)

        End Try
        Panel1.Enabled = False
    End Sub
    Private Sub BijlagetoevoegenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BijlagetoevoegenToolStripMenuItem.Click
        Try
            Dim openfile As New OpenFileDialog
            '     openfile.Filter = "Media Files| *.gif ;*.jpg;*.bmp;*.png;*.ico"
            openfile.Multiselect = False
            If openfile.ShowDialog = DialogResult.OK Then
                TextBox5.Text = openfile.FileName
                Label6.Text = "Bijlage: " + (Path.GetFileName(TextBox5.Text))
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
 
End Class
 
de melding is

de transportfunctie kan geen verbindingen met de server
 
Het zou kunnen dat het CDO object niet bij het Form object kan. Doen dan eens het volgende:

Code:
DIM SMTPserver as string

SMTPserver = Textbox4.Text

objemail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPserver

Het is alleen niet duidelijk of je het nu in Textbox4 of in Textbox6 hebt staan.
 
Ik heb het geprobeerd, weer precies het zelfde:
Heb dus gedaan:
DIM SMTPserver as string

SMTPserver = Textbox4.Text

objemail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPserver

Werkt niet en vervang ik nu:
SMTPserver = Textbox4.Text door:

SMTPserver = "mailhost.hetnet.nl" dan werkt het wel
 
Weet je zeker dat het Textbox4 is en niet Textbox6?
 
Ja klopt wel wat je zegt ik heb per ongeluk hier textbox4 neergezet maar bij mij is het gewoon textbox6
 
Dus? Werkt het nu wel?
 
nee ik wist dit wel die fout maar heb alles wel met mijn eigen textbox6 gedaan, dus werkt het nog steeds helaas niet
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan