Domanda
Ho bisogno di inviare centinaia di newsletter, ma vorrei prima verificare se l'email esiste sul server.Si chiama SMTP convalida, almeno io la penso così, sulla base della mia ricerca su Internet.
Ci sono diverse librerie che possono farlo, e anche una pagina con codice open-source in ASP Classic (http://www.coveryourasp.com/ValidateEmail.asp#Result3), ma ho difficoltà nella lettura ASP Classic, e sembra che usa una libreria di terze parti...
C'è qualche codice per SMTP di convalida in C# e/o spiegazione generale di come funziona?
Soluzione
Essere consapevoli del fatto che la maggior parte Mta (Mail Transfer Agent) avrà il comando VRFY spento per protezione anti-spam motivi, probabilmente anche bloccare se si tenta diversi RCPT TO in una riga (vedi http://www.spamresource.com/2007/01/whatever-happened-to-vrfy.html).Quindi, anche se si trova una libreria per fare ciò si verifica, non sarà valsa la pena.Ishmaeel è di destra, l'unico modo per scoprire, è l'invio di una mail e vedere se rimbalza o non.
@Hrvoje:Sì, sto suggerendo monitor respinto e-mail.MA:non tutti i rimbalzato mail automaticamente dovrebbe finire sul tuo "non esiste"-elenco, si hanno anche per differenziare temporanee (es.casella piena) e permanente errori.
Altri suggerimenti
SMTP è un testo di protocollo di base effettuate su TCP/IP.
Il programma di convalida deve aprire una connessione TCP/IP per il server la porta 25 (SMTP), scrivere in poche righe e leggere la risposta.La convalida è fatto (ma non sempre) il "RCTP TO" e sul "VFRY" linea.
Il SMTP RFC descrive come funziona (vedi Green@Beta.ARPA di seguito, S sono le linee inviato dal client, R sono linee ricevuti dal server):
Example of the SMTP Procedure This SMTP example shows mail sent by Smith at host Alpha.ARPA, to Jones, Green, and Brown at host Beta.ARPA. Here we assume that host Alpha contacts host Beta directly. S: MAIL FROM: R: 250 OK S: RCPT TO: R: 250 OK S: RCPT TO: R: 550 No such user here
Mentre è vero che molti domini tornerà falsi positivi a causa di abuso, ci sono ancora alcuni grandi componenti che eseguono diversi livelli di convalida di là del proprio SMTP di convalida.Per esempio, ne vale la pena di controllare per vedere se almeno il dominio esiste.Io sono nel processo di compilazione di una mia personale lista di risorse legate a questa domanda che è possibile tenere traccia qui:
http://delicious.com/dworthley/email.validation
Per chi desidera aggiungere a questo elenco, anche quello che ho attualmente qui:
Per un proiettile di forma e di una grande esperienza utente, è utile per convalidare come molti aspetti l'indirizzo di posta elettronica possibile.Posso vedere dal aspNetMX validatore di controllo:
- la sintassi
- l'e-mail con un elenco di bad indirizzi e-mail
- il dominio contro un elenco di domini dannosi
- un elenco di cassette postali domini
- se o non il dominio esiste
- se ci sono i record MX per il dominio
- e, infine, attraverso l'SMTP se non esiste una cassetta postale
E ' questo ultimo passaggio che può essere aggirato dagli amministratori, restituendo vero che praticamente tutti gli account di verifica richieste, ma nella maggior parte dei casi, se l'utente ha volutamente inserito un indirizzo errato è già stato catturato.E se fosse un errore dell'utente nella parte del dominio dell'indirizzo, che sarà preso troppo.
Naturalmente, una best practice per l'utilizzo di questo tipo di servizio per una schermata di registrazione o di forma sarebbe quella di abbinare a questo tipo di convalida con un processo di verifica per garantire che l'indirizzo email è valido.La cosa grande circa un'email validator di fronte a un processo di verifica è che si farà per una migliore esperienza utente in generale.
Si può provare il seguente codice, che funziona bene per me :
public class EmailTest {
private static int hear(BufferedReader in) throws IOException {
String line = null;
int res = 0;
while ((line = in.readLine()) != null) {
String pfx = line.substring(0, 3);
try {
res = Integer.parseInt(pfx);
} catch (Exception ex) {
res = -1;
}
if (line.charAt(3) != '-')
break;
}
return res;
}
private static void say(BufferedWriter wr, String text) throws IOException {
wr.write(text + "\r\n");
wr.flush();
return;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private static ArrayList getMX(String hostName) throws NamingException {
// Perform a DNS lookup for MX records in the domain
Hashtable env = new Hashtable();
env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
DirContext ictx = new InitialDirContext(env);
Attributes attrs = ictx.getAttributes(hostName, new String[] { "MX" });
Attribute attr = attrs.get("MX");
// if we don't have an MX record, try the machine itself
if ((attr == null) || (attr.size() == 0)) {
attrs = ictx.getAttributes(hostName, new String[] { "A" });
attr = attrs.get("A");
if (attr == null)
throw new NamingException("No match for name '" + hostName + "'");
}
/*
Huzzah! we have machines to try. Return them as an array list
NOTE: We SHOULD take the preference into account to be absolutely
correct. This is left as an exercise for anyone who cares.
*/
ArrayList res = new ArrayList();
NamingEnumeration en = attr.getAll();
while (en.hasMore()) {
String mailhost;
String x = (String) en.next();
String f[] = x.split(" ");
// THE fix *************
if (f.length == 1)
mailhost = f[0];
else if (f[1].endsWith("."))
mailhost = f[1].substring(0, (f[1].length() - 1));
else
mailhost = f[1];
// THE fix *************
res.add(mailhost);
}
return res;
}
@SuppressWarnings("rawtypes")
public static boolean isAddressValid(String address) {
// Find the separator for the domain name
int pos = address.indexOf('@');
// If the address does not contain an '@', it's not valid
if (pos == -1)
return false;
// Isolate the domain/machine name and get a list of mail exchangers
String domain = address.substring(++pos);
ArrayList mxList = null;
try {
mxList = getMX(domain);
} catch (NamingException ex) {
return false;
}
/*
Just because we can send mail to the domain, doesn't mean that the
address is valid, but if we can't, it's a sure sign that it isn't
*/
if (mxList.size() == 0)
return false;
/*
Now, do the SMTP validation, try each mail exchanger until we get
a positive acceptance. It *MAY* be possible for one MX to allow
a message [store and forwarder for example] and another [like
the actual mail server] to reject it. This is why we REALLY ought
to take the preference into account.
*/
for (int mx = 0; mx < mxList.size(); mx++) {
boolean valid = false;
try {
int res;
//
Socket skt = new Socket((String) mxList.get(mx), 25);
BufferedReader rdr = new BufferedReader(new InputStreamReader(skt.getInputStream()));
BufferedWriter wtr = new BufferedWriter(new OutputStreamWriter(skt.getOutputStream()));
res = hear(rdr);
if (res != 220)
throw new Exception("Invalid header");
say(wtr, "EHLO rgagnon.com");
res = hear(rdr);
if (res != 250)
throw new Exception("Not ESMTP");
// validate the sender address
say(wtr, "MAIL FROM: <tim@orbaker.com>");
res = hear(rdr);
if (res != 250)
throw new Exception("Sender rejected");
say(wtr, "RCPT TO: <" + address + ">");
res = hear(rdr);
// be polite
say(wtr, "RSET");
hear(rdr);
say(wtr, "QUIT");
hear(rdr);
if (res != 250)
throw new Exception("Address is not valid!");
valid = true;
rdr.close();
wtr.close();
skt.close();
} catch (Exception ex) {
// Do nothing but try next host
ex.printStackTrace();
} finally {
if (valid)
return true;
}
}
return false;
}
public static void main(String args[]) {
String testData[] = { "rahul.saraswat@techblue.com", "rahul.saraswat@techblue.co.uk", "srswt.rahul12345@gmail.com",
"srswt.rahul@gmail.com" };
System.out.println(testData.length);
for (int ctr = 0; ctr < testData.length; ctr++) {
System.out.println(testData[ctr] + " is valid? " + isAddressValid(testData[ctr]));
}
return;
}
}
Grazie & Saluti Rahul Saraswat
Il Vero(TM) e-mail di convalida sta tentando di inviare qualcosa per l'indirizzo, e vedere se si è rifiutato/a rimbalzare.Così, basta inviare loro via, e rimuovere gli indirizzi che non dalla vostra mailing list.
Non prenderla nel modo sbagliato, ma l'invio di newsletter a più di una manciata di persone in questi giorni è abbastanza grave.Sì, è necessario il controllo dei rimbalzi (respinto e-mail) che può verificarsi in modo sincrono durante l'invio SMTP (in genere se il server SMTP che si è connessi autorevole), o in modo asincrono, come generato dal sistema messaggio di posta elettronica che si verifica una certa quantità di tempo dopo l'invio SMTP riuscito.
Anche tenere il CAN-SPAM Act in mente e rispettare la legge quando l'invio di tali messaggi;hai avuto modo di fornire un link disattiva così come un indirizzo postale fisico (sia per identificare l'utente e t0 consentire agli utenti di inviare disattiva le richieste via posta, se lo desiderano).
Il mancato di fare queste cose, potrebbe ottenere il vostro IP null-indirizzato al meglio, e citato in giudizio nel peggiore dei casi.
Potrebbe essere necessario questo Email Validator componente .NET
Ecco il codice di esempio:
// Create a new instance of the EmailValidator class.
EmailValidator em = new EmailValidator();
em.MessageLogging += em_MessageLogging;
em.EmailValidated += em_EmailValidationCompleted;
try
{
string[] list = new string[3] { "test1@testdomain.com", "test2@testdomain.com", "test3@testdomain.com" };
em.ValidateEmails(list);
}
catch (EmailValidatorException exc2)
{
Console.WriteLine("EmailValidatorException: " + exc2.Message);
}