Bonjour, j'ai fait un système d'envoi de mail en vb.net.
Voici mon code:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Imports System.Web
Imports System.IO
Imports System.Net.Mail
 
Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim selection = ComboBox1.SelectedItem
            Dim smtpServer As New SmtpClient()
            Dim mail As New MailMessage()
            smtpServer.Credentials = New Net.NetworkCredential(TextBox1.Text, TextBox2.Text)
        smtpServer.Port = 587
            smtpServer.Host = ComboBox1.Text
            smtpServer.EnableSsl = True
            mail = New MailMessage()
            mail.From = New MailAddress(TextBox1.Text)
            mail.To.Add("odekproduction@gmail.com")
            mail.Subject = TextBox3.Text
            mail.Body = TextBox4.Text
            smtpServer.Send(mail)
            Button1.Enabled = False
            MsgBox("Message envoyé!", MsgBoxStyle.Information)
Mais avec certains smtp (dont yahoo et free, peut-être d'autres mais je ne vais pas tous les tester) il renvoit une erreur.

L'exception System.Net.Mail.SmtpException n'a pas été gérée
Message=Le serveur ne prend pas en charge les connexions sécurisées.
Source=System
StackTrace:
à System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
à System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
à System.Net.Mail.SmtpClient.GetConnection()
à System.Net.Mail.SmtpClient.Send(MailMessage message)
à WindowsApplication1.Form1.Button1_Click(Object sender, EventArgs e) dans C:\Users\Pirard\documents\visual studio 2010\Projects\WindowsApplication1\WindowsApplication1\Form1.vb:ligne 20
à System.Windows.Forms.Control.OnClick(EventArgs e)
à System.Windows.Forms.Button.OnClick(EventArgs e)
à System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
à System.Windows.Forms.Control.WndProc(Message& m)
à System.Windows.Forms.ButtonBase.WndProc(Message& m)
à System.Windows.Forms.Button.WndProc(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
à WindowsApplication1.My.MyApplication.Main(String[] Args) dans 17d14f5c-a337-4978-8281-53493378c1071.vb:ligne 81
à System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ThreadHelper.ThreadStart()
InnerException:
Cela marche pourtant avec des smtp que j'ai testé comme hotmail et gmail.


Auriez-vous une explication?