Good day to everyone. I've writen a project based on asp.net mvc3. Part of project is based on sending emails from my application.
大家好日子。我写了一个基于asp.net mvc3的项目。项目的一部分基于从我的应用程序发送电子邮件。
public void SendEmail(string address, string subject, string message, int id)
{
string email = "emailname@gmail.com";
string password = "somepassword";
var loginInfo = new NetworkCredential(email, password);
var msg = new MailMessage();
var smtpClient = new SmtpClient("smtp.gmail.com", 587);
msg.From = new MailAddress(email);
msg.To.Add(new MailAddress(address));
msg.Subject = subject;
msg.Body = message;
msg.IsBodyHtml = true;
msg.Attachments.Add(new Attachment(Server.MapPath("~/Content/StudentPdf/student" + id + ".pdf")));
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = loginInfo;
smtpClient.Send(msg);
}
This code works locally, perfectly sending emails. But when I upload this to the hosting, it causes an error
此代码在本地工作,完美地发送电子邮件。但是当我将其上传到托管服务器时,会导致错误
the SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
SMTP服务器需要安全连接或客户端未经过身份验证。服务器响应为:5.5.1需要身份验证。
I've tried to change port to 465, but then it will be get me an tcp_ip error on the hosting. And one more: and when users try to send emails from this mailbox google tell me that suspicious activity on the application. It's because my hosting in one country and I am in another country.
我试图将端口更改为465,但是它会在主机上收到tcp_ip错误。还有一个:当用户尝试从此邮箱发送电子邮件时谷歌告诉我应用程序上的可疑活动。这是因为我在一个国家的托管,而我在另一个国家。
I have no idea what I have to do next. I've tried googling and found something about 2 level registration, but don't understand how I need implement it in my method.
我不知道接下来要做什么。我已经尝试使用谷歌搜索并找到了关于2级注册的内容,但不明白我需要在我的方法中实现它。
I'm using arvixe hosting. Maybe others have the same problems?
我正在使用arvixe托管。也许其他人有同样的问题?
1 个解决方案
#1
1
Please login into your gmail account manually and allow the IP of your hosting under gmail settings.Thats why i think its working perfectly on your local. Same happened with me and after doing this there was no problem.
请手动登录您的Gmail帐户,并在gmail设置下允许您托管的IP。这就是为什么我认为它在您的本地工作完美。同样的事情发生在我身上,这样做没有问题。
#1
1
Please login into your gmail account manually and allow the IP of your hosting under gmail settings.Thats why i think its working perfectly on your local. Same happened with me and after doing this there was no problem.
请手动登录您的Gmail帐户,并在gmail设置下允许您托管的IP。这就是为什么我认为它在您的本地工作完美。同样的事情发生在我身上,这样做没有问题。