He estado trasteando algo mas con esto pero no doy con ello, tengo mi archivo de la dll, que tiene esto:
Código ASP:
Ver originalclass ValidadorEMail
{
// valores devueltos
// 0 = OK
// 1 = Email mal escrito
// 2 = Email inválido
// 3 = error con dominio valido
// 4 = dominio invalido
// 5 = Sin conexion a internet
public int SevidorEMail(string sEmail, bool SoloSintaxis)
{
NetworkStream oStream;
string sFrom;
string sTo;
string sResponse;
string Remote_Addr;
string mserver;
string[] sText;
int returnvalue = 0;
if (!ValidEmail(sEmail)) return 1;
if (!SoloSintaxis)
{
if (!IsConnected()) return 5;
sTo = "<" + sEmail + ">";
sText = sEmail.Split('@');
mserver = NSLookup(sText[1]);
if (mserver == "")
{
returnvalue = 4;
return returnvalue;
}
Remote_Addr = "datacronos.com";
sFrom = "datacronos@" + Remote_Addr + ">";
TcpClient oConnection = new TcpClient();
try
{
oConnection.SendTimeout = 3000;
oConnection.Connect(mserver, 25);
oStream = oConnection.GetStream();
sResponse = GetData(oStream);
sResponse = TalkToServer(oStream, "HELO " + Remote_Addr + "\n");
sResponse = TalkToServer(oStream, "MAIL FROM: " + sFrom + "\n");
if (ValidResponse(sResponse))
{
sResponse = TalkToServer(oStream, "RCPT TO: " + sTo + "\n");
if (ValidResponse(sResponse))
{
returnvalue = 0;
}
else
{
returnvalue = 2;
}
}
TalkToServer(oStream, "QUIT" + "\n");
oConnection.Close();
oStream = null;
}
catch
{
returnvalue = 3;
}
}
return returnvalue;
}
private bool ValidEmail(string email)
{
String expresion;
expresion = "\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
if (Regex.IsMatch(email, expresion))
{
if (Regex.Replace(email, expresion, String.Empty).Length == 0)
{ return true; }
else { return false; }
}
else { return false; }
}
private string GetData(NetworkStream oStream)
{
byte[] bResponse = new byte[1024];
string sResponse = "";
int lenStream = 0;
lenStream = oStream.Read(bResponse, 0, 1024);
if (lenStream > 0)
{
sResponse = Encoding.ASCII.GetString(bResponse, 0, 1024);
}
return sResponse;
}
private string SendData(NetworkStream oStream, string sToSend)
{
string sResponse;
byte[] bArray = Encoding.ASCII.GetBytes(sToSend.ToCharArray());
oStream.Write(bArray, 0, bArray.Length);
sResponse = GetData(oStream);
return sResponse;
}
private bool ValidResponse(string sResult)
{
bool bResult = false;
int iFirst;
if (sResult.Length > 1)
{
iFirst = Convert.ToInt32(sResult.Substring(0, 1));
if (iFirst < 3) { bResult = true;}
}
return bResult;
}
private string TalkToServer(NetworkStream oStream, string sToSend)
{
string sresponse;
sresponse = SendData(oStream, sToSend);
return sresponse;
}
private string NSLookup(string sDomain)
{
ProcessStartInfo info = new ProcessStartInfo();
info.UseShellExecute = false;
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.FileName = "nslookup";
info.Arguments = "-type=MX " + sDomain.ToUpper().Trim();
info.WindowStyle = ProcessWindowStyle.Hidden;
Process ns;
ns = Process.Start(info);
StreamReader sout;
sout = ns.StandardOutput;
Regex reg = new Regex("mail exchanger = (?<server>[^\\\\\\s]+)");
string mailserver = "";
string response = "";
do
{
response = sout.ReadLine();
Match amatch = reg.Match(response);
Debug.WriteLine(response);
if (amatch.Success) { mailserver = amatch.Groups["server"].Value; }
} while (sout.Peek() > -1);
return mailserver;
}
private static bool IsConnected()
{
int connectionDescription = 0;
return InternetGetConnectedState(out connectionDescription, 0);
}
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
}
Y yo lo estoy intentanto utilizar asi, pero me peta:
Código ASP:
Ver originalImports validaMail
Imports System.Runtime.InteropServices
Public Class pruebasMias
....................................................
<DllImport("validaMail.dll",true)>
Y no sé que parametros y como debo invocar a la dll, a ver si alguien me puede echar una mano.
GRACIAS!!!