Bonjour j’ai rencontrer un problem en Visual Basic 2008 avec le code smtp
J’ai suivis un tutoriel et j’ai taper exactement le même source code du smtp
Donc le voici:
Imports System
Imports System.Web.Mail
Dim Server As String
Dim mailto As String
Dim mailfrom As String
Dim subject As string
Dim msg As String
server = “mail.yahoo.com” 'Le serveur smtp
mailto = “******@yahoo.ca” 'l’email
MailFrom = txtEmail.text
subject = “Feedback”
msg = txtName.text & vbNewLine & “Hacked by Code-sOurce”
smtpMail.smtpServer = server
Try
SmtpMail.Send (mailfrom,mailto,subject,msg)
Catch ex As Exception
Et le message qui s’affiche le voici:
A first chance exception of type ‘System.Web.HttpException’ occurred in System.Web.dll
Sais pas moi, un MsgBox(ex.ToString()) dans le catch et une capture d’écran par exemple :neutre:
Sinon tu vires le try/catch, tu lances l’application avec le debugger (F5 dans Visual Studio), et au moment de l’erreur VS va mettre l’application “en pause” et va t’afficher l’exception. Tu devrais pouvoir faire un copier-coller à partir de là.
Edité le 25/12/2008 à 23:51
Salut,
Quand tu copies/colles du code, essaie de réfléchir un minimum, encore une fois, je ne sais pas pourquoi je t’aide car tu vas à l’encontre de tous mes principes concernant l’apprentissage de la programmation mais bon, c’est noel ('fin on va dire ça) : tu n’as pas vu qu’il y a du vert sous “SmtpMail.”, Visual Studio, c’est pas Picasso et s’il met une couleur c’est qu’il y a une raison, c’est simple, c’est “juste” qu’il n’est déclaré nul part …
De toute facon, cet exemple est obsolete car il passe par l’espace de nom System.Web.Mail alors qu’il vaut mieux maintenant passer par System.Net.Mail, tu as un exemple d’un client stmp tout près ici …
Edité le 26/12/2008 à 18:15
Merci ton cadeau est super
Donc si j’ai bien compris a la place de “System.Web.Mail” je mes “System.Net.Mail”
Et la sa va marcher ??
j’attend ta réponse avec impatience:D
Imports System
Imports System.Net
Imports System.Net.Mail
Imports System.Net.Mime
Imports System.Threading
Imports System.ComponentModel
Namespace Examples.SmptExamples.Async
Class SimpleAsynchronousExample
Private Shared mailSent As Boolean = false
Private Shared Sub SendCompletedCallback(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs)
' Get the unique identifier for this asynchronous operation.
Dim token As String = CType(e.UserState,String)
If e.Cancelled Then
Console.WriteLine("[{0}] Send canceled.", token)
End If
If (Not (e.Error) Is Nothing) Then
Console.WriteLine("[{0}] {1}", token, e.Error.ToString)
Else
Console.WriteLine("Message sent.")
End If
mailSent = true
End Sub
Public Shared Sub Main(ByVal args() As String)
' Command line argument must the the SMTP host.
Dim client As SmtpClient = New SmtpClient(args(0))
' Specify the e-mail sender.
' Create a mailing address that includes a UTF8 character
' in the display name.
Dim from As MailAddress = New MailAddress("jane@contoso.com", ("Jane " _
+ (CType(216,Char) + " Clayton")), System.Text.Encoding.UTF8)
' Set destinations for the e-mail message.
Dim to As MailAddress = New MailAddress("ben@contoso.com")
' Specify the message content.
Dim message As MailMessage = New MailMessage(from, to)
message.Body = "This is a test e-mail message sent by an application. "
' Include some non-ASCII characters in body and subject.
Dim someArrows As String = New String(New Char() {Microsoft.VisualBasic.ChrW(92), Microsoft.VisualBasic.ChrW(92), Microsoft.VisualBasic.ChrW(92), Microsoft.VisualBasic.ChrW(92)})
message.Body = (message.Body _
+ (Environment.NewLine + someArrows))
message.BodyEncoding = System.Text.Encoding.UTF8
message.Subject = ("test message 1" + someArrows)
message.SubjectEncoding = System.Text.Encoding.UTF8
' Set the method that is called back when the send operation ends.
AddHandler client.SendCompleted, AddressOf Me.SendCompletedCallback
' The userState can be any object that allows your callback
' method to identify this send operation.
' For this example, the userToken is a string constant.
Dim userState As String = "test message1"
client.SendAsync(message, userState)
Console.WriteLine("Sending message... press c to cancel mail. Press any other key to exit.")
Dim answer As String = Console.ReadLine
' If the user canceled the send, and mail hasn't been sent yet,
' then cancel the pending operation.
If (answer.StartsWith("c") _
AndAlso (mailSent = false)) Then
client.SendAsyncCancel
End If
' Clean up.
message.Dispose
Console.WriteLine("Goodbye.")
End Sub
End Class
End Namespace
Qu’est ce que tu comprends pas la dedans, le fait que ce soit en anglais ?
Dim Server As String
Dim mailto As String
Dim mailfrom As String
Dim subject As string
Dim msg As String
server = “mail.yahoo.com” 'Your server smtp
mailto = "caporalpitou007@yahoo.com" 'You email
MailFrom = txtEmail.text
subject = “Feedback”
msg = txtName.text & vbNewLine & “Hacked by Code-sOurce”
smtpMail.smtpServer = server
Try
SmtpMail.Send (mailfrom,mailto,subject,msg)
Catch ex As Exception
MsgBox “Did not work!”