Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
ASP.NET 2.0 / 3.5 / 4.0
Invio mail "massivo"
mercoledì 11 giugno 2008 - 12.55
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
squilibrio
Profilo
| Expert
527
messaggi | Data Invio:
mer 11 giu 2008 - 12:55
Ciao a tutti, vorrei creare una procedura che invia mail (tramite .NET) partendo da un elenco...
dando per scontato di avere già il ciclo con le info per l'invio (indirizzo mail e testo)
Grazie mille!!!
19018
Profilo
| Expert
502
messaggi | Data Invio:
mer 11 giu 2008 - 13:01
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;
namespace SmtpMail
{
class Program
{
/// <summary>
/// Console App to send mails via Smtp
/// </summary>
/// <param name="args[0]">From</param>
/// <param name="args[1]">To</param>
/// <param name="args[2]">Subject</param>
/// <param name="args[3]">Body</param>
/// <param name="args[4]">Host</param>
/// <param name="args[5]">Port</param>
/// <param name="args[6]">User</param>
/// <param name="args[7]">Password</param>
static void Main(string[] args)
{
try
{
// TODO: Add error handling for invalid arguments
// To
MailMessage mailMsg = new MailMessage();
mailMsg.To.Add(args[1]);
// From
MailAddress mailAddress = new MailAddress(args[0]);
mailMsg.From = mailAddress;
// Subject and Body
mailMsg.Subject = args[2];
mailMsg.Body = args[3];
// Init SmtpClient and send
SmtpClient smtpClient = new SmtpClient(args[4], Convert.ToInt32(args[5]));
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(args[5], args[5]);
smtpClient.Credentials = credentials;
smtpClient.Send(mailMsg);
}
catch (Exception ex)
{
Console.WriteLine( ex.Message );
}
}
}
}
Sistemalo in un ciclo ed ogni volta passi i user e pwd che ti servono!
ciao
Stefano Passatordi
http://blogs.dotnethell.it/stem/
squilibrio
Profilo
| Expert
527
messaggi | Data Invio:
mer 11 giu 2008 - 23:31
Prima di tutto ti ringrazio per l'aiuto!
non capisco cosa intendi per "login" e "password" ... intendi per il server SMTP?? (potrei non avere login e password oppure dico una fesseria??)
// Init SmtpClient and send
SmtpClient smtpClient = new SmtpClient(args[4], Convert.ToInt32(args[5]));
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(args[5], args[5]);
smtpClient.Credentials = credentials;
e questo cosa sarebbe??? cosa fa esattamente?
Grazie ancora!!!!
19018
Profilo
| Expert
502
messaggi | Data Invio:
mer 11 giu 2008 - 23:40
Dipende dal server SMTP che usi, in genere richiedono user e pwd.
Se a te non servono user e pwd perchè il tuo server SMTP ti permette di inviare email senza autenticazione allora elimina :
// Init SmtpClient and send
SmtpClient smtpClient = new SmtpClient(args[4], Convert.ToInt32(args[5]));
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(args[6], args[7]);
smtpClient.Credentials = credentials;
Questa parte serve appunto ad impostare le credenziali di accesso.
ciao
Stefano Passatordi
http://blogs.dotnethell.it/stem/
squilibrio
Profilo
| Expert
527
messaggi | Data Invio:
ven 13 giu 2008 - 01:50
Grazie mille!!!
squilibrio
Profilo
| Expert
527
messaggi | Data Invio:
ven 13 giu 2008 - 01:53
ma questo
NetworkCredential(args[6], args[7]);
pre cosa sta?
in un msg precedente avevi messo 5 5 ed ora 6 7
19018
Profilo
| Expert
502
messaggi | Data Invio:
ven 13 giu 2008 - 09:58
Mi ero confuso...lì vanno user e pwd, invece prima avevo sbagliato. Prima avevo messo la porta
Vedi :
/// <param name="args[0]">From</param>
/// <param name="args[1]">To</param>
/// <param name="args[2]">Subject</param>
/// <param name="args[3]">Body</param>
/// <param name="args[4]">Host</param>
/// <param name="args[5]">Port</param>
/// <param name="args[6]">User</param>
/// <param name="args[7]">Password</param>
ciao
Stefano Passatordi
http://blogs.dotnethell.it/stem/
Torna su
Stanze Forum
Elenco Threads
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?
Dopo esserti registrato potrai chiedere
aiuto sul nostro
Forum
oppure aiutare gli altri
Consulta le
Stanze
disponibili.
Registrati ora !