Envoi du mail en asp.net mvc3

fatnassiimen - 26 mars 2013 à 09:42
 fatnassiimen - 28 mars 2013 à 09:51
Bonjour,

J'ai un formulaire d'inscription et je veux que lors d'un clique sur le bouton 'Create' tous ces informations seront enregistrés dans la base de données plu exactement dans ma table "Vendeur" et un mail envoyé à l'utilisateur qui a fait l'inscrit sur le mail qui la saisir au moment de l'inscrit.
Bon j'ai réussit a faire cette formulaire et enregistrer ces information dans ma table mai je suis bloqué au niveau de l'envoi du mail.
comment le faire en utilisant asp.net mvc 3 ?

Voila mon view de l'inscription:
@model PFE.Models.Vendeur

@{
ViewBag.Title = "Inscription";
}

Inscription






@using (Html.BeginForm()) {
@Html.ValidationSummary(true)

Vendeur



@Html.LabelFor(model => model.NOM)




@Html.EditorFor(model => model.NOM)
@Html.ValidationMessageFor(model => model.NOM)





@Html.LabelFor(model => model.TEL1)




@Html.EditorFor(model => model.TEL1)
@Html.ValidationMessageFor(model => model.TEL1)





@Html.LabelFor(model => model.TEL2)




@Html.EditorFor(model => model.TEL2)
@Html.ValidationMessageFor(model => model.TEL2)





@Html.LabelFor(model => model.FAX)




@Html.EditorFor(model => model.FAX)
@Html.ValidationMessageFor(model => model.FAX)





@Html.LabelFor(model => model.ADRESSE)




@Html.EditorFor(model => model.ADRESSE)
@Html.ValidationMessageFor(model => model.ADRESSE)





@Html.LabelFor(model => model.CODEP)




@Html.EditorFor(model => model.CODEP)
@Html.ValidationMessageFor(model => model.CODEP)





@Html.LabelFor(model => model.VILLE)




@Html.EditorFor(model => model.VILLE)
@Html.ValidationMessageFor(model => model.VILLE)





@Html.LabelFor(model => model.PAYS)




@Html.EditorFor(model => model.PAYS)
@Html.ValidationMessageFor(model => model.PAYS)





@Html.LabelFor(model => model.MAIL)




@Html.EditorFor(model => model.MAIL)
@Html.ValidationMessageFor(model => model.MAIL)





@Html.LabelFor(model => model.CODE)




@Html.EditorFor(model => model.CODE)
@Html.ValidationMessageFor(model => model.CODE)





@Html.LabelFor(model => model.Type)




@Html.EditorFor(model => model.Type)
@Html.ValidationMessageFor(model => model.Type)









}



@Html.ActionLink("Back to List", "Index")





et voila mon controlleur:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PFE.Models;
using System.Web.Helpers;

namespace PFE.Controllers
{
public class InscriptionController : Controller
{
private WEBMEDEntities1 db = new WEBMEDEntities1();


//
// GET: /Inscription/

public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(Vendeur vendeur)
{

if (ModelState.IsValid)
{
db.Vendeur.AddObject(vendeur);
db.SaveChanges();
return RedirectToAction("Confirmation", "Confirmation");//redireger vers une page contenet un message "Pour confirmer l'inscription,un mail de validation sera envoyé sur l'adresse mail que vous avez saisir au momant de l'inscription"
}
return View();
}
}
}

2 réponses

cs_jopop Messages postés 1540 Date d'inscription lundi 26 mai 2003 Statut Membre Dernière intervention 1 août 2013 12
27 mars 2013 à 19:33
Salut,

je ne connais pas les spécificités des appli MVC .NET, mais regarde du côté du namespace System.Net.Mail, tu y trouveras le code "normal" d'un envoi de mail en .NET
0
fatnassiimen
28 mars 2013 à 09:51
Bonjour,
D'accord ok merci pour la reponce :)
0
Rejoignez-nous