CF.NET SMTP - 使用 Gmail 发送电子邮件

发布于 2024-09-09 10:57:26 字数 2027 浏览 5 评论 0原文

我正在尝试从我的应用程序发送电子邮件。 我可以通过 smtp.mail.yahoo.com 发送电子邮件,但是当我尝试使用 gmail (smtp.gmail.com) 发送电子邮件时,它失败了。

我正在使用 SocketPro。

我也尝试过使用 openSSL 但我不知道如何使用它!

任何人,您有任何代码示例,可以提供给我,从 Gmail 发送电子邮件吗?

我有以下问题:

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: <[email protected]>"));
m_ClientSocket.Send(Encoding.UTF8.GetBytes("\r\n"));
m_ClientSocket.Send(Encoding.UTF8.GetBytes("RCPT TO: <[email protected]>"));
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: <[email protected]>"));
m_ClientSocket.Send(Encoding.UTF8.GetBytes("To: <[email protected]>"));
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"));

你能帮我吗?

谢谢。

安德鲁

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: <[email protected]>"));
m_ClientSocket.Send(Encoding.UTF8.GetBytes("\r\n"));
m_ClientSocket.Send(Encoding.UTF8.GetBytes("RCPT TO: <[email protected]>"));
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: <[email protected]>"));
m_ClientSocket.Send(Encoding.UTF8.GetBytes("To: <[email protected]>"));
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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

当爱已成负担 2024-09-16 10:57:26

我不知道这是否有帮助,但 GMail SMTP 服务器要求您在端口 465 上使用 SSL。

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

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

李白 2024-09-16 10:57:26

为什么不使用.Net Smtp 客户端? (在 System.Net.Mail 命名空间中)

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文