Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

authentification smpt

3 réponses
Avatar
Sylfelin
Bonjour,

Soit l'extrait de code ci-dessous sur une page aspx.
Comment faire une authentification SMTP ?

Merci

private System.Net.Mail.MailMessage _mail = New
System.Net.Mail.MailMessage();

public bool Envoyer
{
this._mail.Subject = subject;
this._mail.From = new System.Net.Mail.MailAddress(fromMail, fromName);
this._mail.To.Add(new System.Net.Mail.MailAddress(toMail, toName));

try
{
System.Net.Mail.SmtpClient smtp =
new System.Net.Mail.SmtpClient("smtp.fr.oleane.com");
smtp.Port = 25;
smtp.Send(this._mail);
return true;
}
catch (Exception) { return false;
}
}

--

--------------------------
Merci
Sylfelin

3 réponses

Avatar
Arnaud CLERET
Bonsoir,

Il est nécessaire de rajouter les propriétés suivantes à votre objet
MailMessage :
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", userName);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);

--
arno - http://www.dotnetguru2.org/acleret/


"Sylfelin" a écrit :

Bonjour,

Soit l'extrait de code ci-dessous sur une page aspx.
Comment faire une authentification SMTP ?

Merci

private System.Net.Mail.MailMessage _mail = New
System.Net.Mail.MailMessage();

public bool Envoyer
{
this._mail.Subject = subject;
this._mail.From = new System.Net.Mail.MailAddress(fromMail, fromName);
this._mail.To.Add(new System.Net.Mail.MailAddress(toMail, toName));

try
{
System.Net.Mail.SmtpClient smtp > new System.Net.Mail.SmtpClient("smtp.fr.oleane.com");
smtp.Port = 25;
smtp.Send(this._mail);
return true;
}
catch (Exception) { return false;
}
}

--

--------------------------
Merci
Sylfelin





Avatar
Sylfelin
> Il est nécessaire de rajouter les propriétés suivantes à votre objet
MailMessage :
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",
"1");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",
userName);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",
password);




Le problème c'est qu'en dot.net 2 fields est n'existe pas.

--

--------------------------
Merci
Sylfelin
Avatar
Arnaud CLERET
Bonjour,

En effet ! Et pourtant la doc MSDN indique que cette propriété existe
toujours en .Net 2.0 :(

A priori, il est donc nécessaire d'affecter un Credential à l'objet
SmtpClient comme suit :
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential(userName, password, domain);
...
cleint.Send(message);

--
arno - http://www.dotnetguru2.org/acleret/


"Sylfelin" a écrit :

> Il est nécessaire de rajouter les propriétés suivantes à votre objet
> MailMessage :
> mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",
> "1");
> mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",
> userName);
> mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",
> password);
>

Le problème c'est qu'en dot.net 2 fields est n'existe pas.

--

--------------------------
Merci
Sylfelin