无法向Google帐户发送电子邮件 [英] Can't Send an Email to google accounts
问题描述
大家好。我目前在发送电子邮件时遇到麻烦。这是代码:
Hello guys. I''m currently having troubles with sending an email. Here''s the code:
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("mygoogleaccount@gmail.com");
mail.To.Add(txtemail.Text);
mail.Subject = "Registration Successful";
mail.Body = "Your password is " + pw + ". You can now logon to your account.";
SmtpServer.Port = 25;
SmtpServer.Credentials = new System.Net.NetworkCredential("mygoogleaccount@gmail.com", "mypassword");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
它可以发送电子邮件给@live和@yahoo,但不能发送到google / gmail。请帮帮我......谢谢大家!
缺少引号添加到修复字符串格式[/ edit]
推荐答案
Richard MacCutchan提到它可能在垃圾邮件中。实际上,一切都转移到那里,所以我的案子现在已经关闭。谢谢Richard MacCutchan!
Richard MacCutchan mentioned that it might be in the spam. Actually, everything are transferred there so my case is now closed. Thanks Richard MacCutchan!
Microsoft .NET框架提供两个名称空间,System.Net和System.Net.Sockets,用于应用程序可用于通过Internet发送或接收数据的Internet协议的托管实现。 SMTP协议用于从C#发送电子邮件。 SMTP代表简单邮件传输协议。 C#使用System.Net.Mail命名空间发送电子邮件。我们可以实例化SmtpClient类并分配主机和端口。使用SMTP的默认端口是25,但它可能会有不同的邮件服务器。
以下C#源代码显示如何使用SMTP服务器从Gmail地址发送电子邮件。 Gmail SMTP服务器名称为smtp.gmail.com,使用发送邮件的端口为587,并且还使用NetworkCredential进行基于密码的身份验证。
SmtpClient SmtpServer =新的SmtpClient( smtp.gmail.com);
SmtpServer.Port = 587;
SmtpServer.Credentials =
new System.Net.NetworkCredential( username,password);
The Microsoft .NET framework provides two namespaces, System.Net and System.Net.Sockets for managed implementation of Internet protocols that applications can use to send or receive data over the Internet . SMTP protocol is using for sending email from C#. SMTP stands for Simple Mail Transfer Protocol . C# using System.Net.Mail namespace for sending email . We can instantiate SmtpClient class and assign the Host and Port . The default port using SMTP is 25 , but it may vary different Mail Servers .
The following C# source code shows how to send an email from a Gmail address using SMTP server. The Gmail SMTP server name is smtp.gmail.com and the port using send mail is 587 and also using NetworkCredential for password based authentication.
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
SmtpServer.Port = 587;
SmtpServer.Credentials =
new System.Net.NetworkCredential("username", "password");
using System;
using System.Windows.Forms;
using System.Net.Mail;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("your_email_address@gmail.com");
mail.To.Add("to_address");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail from GMAIL";
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
MessageBox.Show("mail Send");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
你必须提供必要的信息,比如你的gmail用户名和密码等。
You have to provide the necessary information like your gmail username and password etc.
亲爱的gaga blues
每个服务器的SMTP服务器设置都不一样。
(unforunatly ..)
但是这个信息是公开的。
你应该只是谷歌SMTP设置gmail(或任何其他)
我找到了这个简短的gmail要求列表:
Gmail SMTP服务器地址:smtp.gmail.com
Gmail SMTP用户名:您的完整Gmail地址(例如:example@gmail.com)
Gmail SMTP密码:您的Gmail密码
Gmail SMTP端口:465
Gmail SMTP TLS / SSL要求:是的
所以你想把这个代码用于gmail:
Dear gaga blues
SMTP server settings are not the same for every server.
(unforunatly..)
However this info is public.
You should just google SMTP settings gmail (or any other)
I found this brief list of requirements for gmail:
Gmail SMTP server address: smtp.gmail.com
Gmail SMTP user name: Your full Gmail address (e.g. example@gmail.com)
Gmail SMTP password: Your Gmail password
Gmail SMTP port: 465
Gmail SMTP TLS/SSL required: yes
So you want to use this code for gmail:
SmtpServer.Port = 587;
SmtpServer.EnableSsl = true;
希望这是对你有用。
Bert
Hope this is usefull for you.
Bert
这篇关于无法向Google帐户发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!