简体   繁体   中英

CF.NET SMTP - send email with Gmail

I'm trying to send email from my application. I can send email by smtp.mail.yahoo.com, however while I'm trying to send the email with gmail (smtp.gmail.com) it fails.

I'm using SocketPro.

I've try to use also openSSL but I don't know how to use it!

Anyone you have any code sample, that you can provide me, to send email from Gmail?

I have the following:

USocketClass m_ClientSocket;
m_ClientSocket.Send(Encoding.UTF8.GetBytes("EHLO smtp.gmail.com \r\n")); 
m_ClientSocket.Send(Encoding.UTF8.GetBytes("AUTH LOGIN"));
m_ClientSocket.Send(Encoding.UTF8.GetBytes("\r\n"));
m_ClientSocket.Send(Encoding.UTF8.GetBytes(EncodeTo64(myUser)));
m_ClientSocket.Send(Encoding.UTF8.GetBytes("\r\n"));
m_ClientSocket.Send(Encoding.UTF8.GetBytes(EncodeTo64(myPass))); 
m_ClientSocket.Send(Encoding.UTF8.GetBytes("\r\n"));
m_ClientSocket.Send(Encoding.UTF8.GetBytes("MAIL FROM: <aaa@gmail.com>"));
m_ClientSocket.Send(Encoding.UTF8.GetBytes("\r\n"));
m_ClientSocket.Send(Encoding.UTF8.GetBytes("RCPT TO: <bbbbb@gmail.com>"));
m_ClientSocket.Send(Encoding.UTF8.GetBytes("\r\n")); 
m_ClientSocket.Send(Encoding.UTF8.GetBytes("DATA"));
m_ClientSocket.Send(Encoding.UTF8.GetBytes("\r\n"));
m_ClientSocket.Send(Encoding.UTF8.GetBytes("From: <aaa@gmail.com>"));
m_ClientSocket.Send(Encoding.UTF8.GetBytes("To: <bbbbb@gmail.com>"));
m_ClientSocket.Send(Encoding.UTF8.GetBytes("Subject: Test subject"));
m_ClientSocket.Send(Encoding.UTF8.GetBytes("My body test"));
m_ClientSocket.Send(Encoding.UTF8.GetBytes("."));
m_ClientSocket.Send(Encoding.UTF8.GetBytes("\r\n"));
m_ClientSocket.Send(Encoding.UTF8.GetBytes("QUIT"));

can you help me?

Thanks.

Andrew

I don't know if this helps, but GMail SMTP servers require you use SSL on port 465.

Source: http://mail.google.com/support/bin/answer.py?answer=76147

Why not use the .Net Smtp client? (In the System.Net.Mail namespace)

        SmtpClient client = new SmtpClient();
        client.Credentials = new System.Net.NetworkCredential("username", "password");
        client.Host = "some.smtpserver.com";
        client.Send(from, to, subject, body);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM