Thread View: pl.comp.lang.vbasic
2 messages
2 total messages
Started by Maciej Franciszkowski
Tue, 16 Feb 2010 14:39
Jak uwierzytelnić serwer smtp wewnątrz kodu?
Author: Maciej Franciszkowski
Date: Tue, 16 Feb 2010 14:39
Date: Tue, 16 Feb 2010 14:39
31 lines
2312 bytes
2312 bytes
Poniższy kod kończy się błędem spowodowanym brakiem
uwierzytelnienia
Sub MailToAdmin()
Dim smtp As New SmtpClient("127.000.000.001")
Dim mail As New MailMessage()
Dim MessageSM As String
'create the mail message
Try
'set the addresses
mail.From = New
MailAddress("technologia.automat@wella.pl")
mail.To.Add("admin@wella.pl")
'set the content
mail.Subject = "text nagłówka"
mail.Body = "Body messedża"
'send the message
smtp.Send(mail)
Catch myExceptionSM As Exception
MessageSM = "There is error: " +
myExceptionSM.ToString()
MsgBox(MessageSM)
Finally
End Try
End Sub
Re: Jak uwierzytelnić serwer smtp wewnątrz kodu?
Author: Ender
Date: Fri, 19 Feb 2010 08:13
Date: Fri, 19 Feb 2010 08:13
47 lines
2795 bytes
2795 bytes
Witam
Poniżej kod do wysyłki asynchronicznej:
Sub WyslijPoczte()
Dim SerwerSMTP As New Net.Mail.SmtpClient("twoj_serwer_smtp", 25)
Dim Mojadres As New Net.Mail.MailAddress("twojAdres_mailowy")
Dim OdbiorcyAdres As New Net.Mail.MailAddress(txt_Do.Text)
Dim Poczta As New Net.Mail.MailMessage(Mojadres, OdbiorcyAdres)
Poczta.Subject = "temat"
Poczta.Body = "tekst"
Dim T As Net.Mail.Attachment
T = New Net.Mail.Attachment(nazwa_pliku)
Poczta.Attachments.Add(T)
SerwerSMTP.Credentials = New
System.Net.NetworkCredential("twojekonto", "hasło")
Try
Dim EE As Object
EE = Poczta
AddHandler SerwerSMTP.SendCompleted, AddressOf
SmtpClient_OnCompleted
SerwerSMTP.SendAsync(Poczta, EE)
Catch ex As Exception
MsgBox("Nie wysłano wiadomości z powodu błędu:" & Chr(10) &
ex.Message)
End Try
End Sub
Public Sub SmtpClient_OnCompleted(ByVal sender As Object, ByVal e As
System.ComponentModel.AsyncCompletedEventArgs)
If e.Cancelled = True Then
MsgBox("Wiadomość została anulowana")
Application.Exit()
End If
If IsNothing(e.Error) = False Then
MsgBox("Wystąpił błąd przy wysyłaniu wiadomości")
Application.Exit()
Else
MsgBox("Wiadomosć została wysłana")
Application.Exit()
End If
End Sub
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads