[PROGRAMMAZIONE] Posta elettronica
Posted by nous on 22-05-2003 17:10
Allora...sono un pivello,cmq ho un dubbio che solo voi potete risolvermi (spero).
Allora..se voglio mandare una mail col c# è facile,memori del fatto che la gente per la posta elettronica in ASP usava CDONTS hanno deciso di concederci un oggettino carinissimo che fa tutto lui.
Ergo questo funziona (e funziona perchè l'ho provato...un giorno uso Windows.Form e ne faccio un programma per win anzichè per console...)

code:
// created on 17/05/2003 at 18.31 using System; using System.Web.Mail; namespace myMail { public class ClsMail { private string mTxtEmailTo; //Indirizzo destinatario private string mTxtEmailFrom;// Indirizzo mittente private string mTxtMailSubj; // oggetto della mail private string mTxtMailBody; //corpo della mail private string mTxtServerName; //server smtp public ClsMail() { Console.WriteLine ("Mail sender by the Nous"); Console.WriteLine ("-----------------------"); mTxtEmailFrom = ""; mTxtEmailTo = ""; } public string SmtpServer { set { mTxtServerName = value; SmtpMail.SmtpServer = value; } get { return mTxtServerName; } } public string EmailFrom { set { mTxtEmailFrom = value; } get { return mTxtEmailFrom; } } public string EmailTo { set { mTxtEmailTo = value; } get { return mTxtEmailTo; } } public string MailBody { set { mTxtMailBody = value; } get { return mTxtMailBody; } } public string MailSubject { set { mTxtMailSubj = value; } get { return mTxtMailSubj; } } public bool SendNow() { try { Console.WriteLine(); Console.WriteLine("Connessione a : {0}" , mTxtServerName); SmtpMail.Send (mTxtEmailFrom,mTxtEmailTo,mTxtMailSubj, mTxtMailBody); return true; } catch (Exception e) { Console.WriteLine("Errore nell'invio del messaggio : {0}" , e.Message ); return false; } } [STAThread] static void Main(string[] args) { ClsMail Smtp = new ClsMail(); Console.Write("Smtp server : "); Smtp.SmtpServer = Console.ReadLine(); Console.Write("Indirizzo mail del mittente : "); Smtp.EmailFrom = Console.ReadLine(); Console.Write("Indirizzo mail del destinatario : "); Smtp.EmailTo = Console.ReadLine(); Console.Write("Oggetto : "); Smtp.MailSubject = Console.ReadLine(); Console.Write("Testo : "); Smtp.MailBody = Console.ReadLine(); if (Smtp.SendNow()) { Console.WriteLine("Invio riuscito"); } else { Console.WriteLine("Invio fallito"); } } } }


Ma...e qui casca l'asino...se volessi collegarmi al server Pop3 (o IMAP) e comunicarci?Come si fa??
Volendo ottenere qualcosa tipo Pine però in C# (prima di copiare Outlook devo emulare Pine) come cavolo convinco il server Pop3 a collaborare??
Grazie a chi mi aiuta,magari postando un pò di codice.
Powered by: vbHome (lite) v3.8 and vBulletin v2.3.1
Copyright © 2000 - 2002 Jelsoft Enterprises Limited