Stránka 1 z 1

Error se SmtpClientem

Napsal: 19 bře 2012 20:49
od Grow
Ahoj, omlouvám se, že zase otravuji, ale jinak to nejde. Sem v koncích. Potřeboval bych do závorky v tomhle kodu

Kód: Vybrat vše

Dim SMTPServer As New SmtpClient(tady)
připsat aby to přečetlo text v Label3. Zkusil sem tam dát Label3.Text tak to napsalo chybu, zkusil sem místo Labelu dát TextBox ale taky to nejde. Nevíte jak bych to mohl udělat, aby nebyl error a fungovalo to jak má?
Díky.

Re: Error se SmtpClientem

Napsal: 20 bře 2012 07:58
od CZechBoY
"napsalo to chybu".. jakou?

Re: Error se SmtpClientem

Napsal: 20 bře 2012 15:36
od Grow
Tady přikládám foto s chybou

Re: Error se SmtpClientem

Napsal: 21 bře 2012 01:09
od CZechBoY
píše to, že si objekt neinicializoval, ale rovnou použil
Můžeš sem hodit kod?

Re: Error se SmtpClientem

Napsal: 22 bře 2012 16:03
od Grow
Jasně, můžu. Tady je:

Kód: Vybrat vše

Imports System.Net.Mail


Public Class Form1

    Dim SMTPServer As New SmtpClient("smtp." + ComboBox1.Text)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If ComboBox1.Text = "Zoznam.sk" Then
            Label4.Text = 587
            usernamebox.Text = "@zoznam.sk"
        End If

        If ComboBox1.Text = "Atlas.cz" Then
            Label4.Text = 25
            usernamebox.Text = "@atlas.cz"
        End If

        If ComboBox1.Text = "Centrum.cz" Then
            Label4.Text = 25
            usernamebox.Text = "@centrum.cz"
        End If

        If ComboBox1.Text = "GMAIL.cz" Then
            Label4.Text = 587
            usernamebox.Text = "@gmail.com"
        End If

        Dim MyMailMessage As New MailMessage()
        MyMailMessage.From = New MailAddress(usernamebox.Text)
        MyMailMessage.To.Add(tobox.Text)
        MyMailMessage.Subject = (subject.Text)
        MyMailMessage.Body = message.Text

        SMTPServer.Port = Label4.Text
        SMTPServer.Credentials = New System.Net.NetworkCredential(usernamebox.Text, passwordbox.Text)
        SMTPServer.EnableSsl = True
        SMTPServer.Send(MyMailMessage)

        Form2.Show()
        Me.Hide()

       
    End Sub
End Class

Re: Error se SmtpClientem

Napsal: 22 bře 2012 17:16
od CZechBoY
ten kod na přiřazení hodnoty proměnný SMTPServer musíš dát do nějaký metody, nemůžeš hned číst z komponenty, která není inicializovaná

Re: Error se SmtpClientem

Napsal: 22 bře 2012 17:23
od Grow
Upravil sem script tak mrkni teď.... Kámošovi to ve VB2010 jde bez problému... Do jaké metody máš namysli?

Re: Error se SmtpClientem  Vyřešeno

Napsal: 22 bře 2012 19:07
od CZechBoY
VB.NET píše:Imports System.Net.Mail


Public Class Form1

Dim SMTPServer As SmtpClient

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

If ComboBox1.Text = "Zoznam.sk" Then
Label4.Text = 587
usernamebox.Text = "@zoznam.sk"
End If

If ComboBox1.Text = "Atlas.cz" Then
Label4.Text = 25
usernamebox.Text = "@atlas.cz"
End If

If ComboBox1.Text = "Centrum.cz" Then
Label4.Text = 25
usernamebox.Text = "@centrum.cz"
End If

If ComboBox1.Text = "GMAIL.cz" Then
Label4.Text = 587
usernamebox.Text = "@gmail.com"
End If

Dim MyMailMessage As New MailMessage()
MyMailMessage.From = New MailAddress(usernamebox.Text)
MyMailMessage.To.Add(tobox.Text)
MyMailMessage.Subject = (subject.Text)
MyMailMessage.Body = message.Text

SMTPServer=New SmtpClient("smtp." + ComboBox1.Text)
SMTPServer.Port = Label4.Text
SMTPServer.Credentials = New System.Net.NetworkCredential(usernamebox.Text, passwordbox.Text)
SMTPServer.EnableSsl = True
SMTPServer.Send(MyMailMessage)

Form2.Show()
Me.Hide()


End Sub
End Class


dal jsem to do kliknutí tlačítka (nechtělo se mi vytvářet metodu Form_Load a handler..)
doufám, že to takhle pude, VB už neumim a už ho ani nemám ve VisualStudiu

pokud to chceš načíst hned při načtení formuláře tak do Form_Load :)

Re: Error se SmtpClientem

Napsal: 22 bře 2012 21:28
od Grow
Díky moc. Už to funguje. Moc si mi pomohl... Co sem dlužnej?