Sendmail使用SMTP服务器... [英] Sendmail using SMTP server...

查看:265
本文介绍了Sendmail使用SMTP服务器...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是尝试使用C#生成电子邮件,但是,我认为我使用了错误的SMTP服务器,因为Gmail出于某种原因超时。 Google邮件是否需要在发件人地址或某些身份验证机制上进行安全配置,因为这显然是一个垃圾邮件电子邮件示例?



你会建议什么?



试试
{
MailMessage m = new MailMessage();
m.Subject =test;
m.From = new MailAddress(president@usa.gov);
m.To.Add(camilleri.jon@gmail.com);
SmtpClient smtp = new SmtpClient(smtp.gmail.com);
smtp.Send(m);
}
catch(Exception ex){Console.WriteLine(ex.Source); }

解决方案

拥有邮件服务器地址并不代表你可以使用它。



通常,您需要以某种方式进行身份验证,可能只是从其域中进行查询。由于您没有从适当的位置(谷歌的某些部分)提出请求,您将被服务器拒绝。



作为实验,请将邮件服务器切换为客户端经过身份验证的系统的服务器。这 可以 工作。




< blockquote>我最近开发了一个代码作为网站联系页面的一部分,需要在这里发送电子邮件是代码。



  var  sender = contact.Email; 

var email = new MailMessage();
email.To.Add( new MailAddress( arnaldo.skywalker@caudal.cu));
email.From = new MailAddress( arnaldo@caudal.cu);
email.Subject = form [ Tipo de contacto] + de + sender;
email.Body = contact.Message;
email.IsBodyHtml = true ;
email.Priority = MailPriority.Normal;

var smtp = new SmtpClient
{
Host = 192.168.145.209
Port = 25
EnableSsl = false
UseDefaultCredentials = false
Credentials = new NetworkCredential( arnaldo@caudal.cu lade


23 )
};

尝试
{
smtp.Send(email);

var verificationEmail = new MailMessage();
verificationEmail.To.Add( new MailAddress(sender));
verificationEmail.From = new MailAddress( arnaldo@caudal.cu);
verificationEmail.Subject = Su + form [ Tipo de contacto] + seráatendida +发件人;
verificationEmail.Body = Atenderemos su + form [ Tipo de contacto] + la la mayor brevedad posible;
verificationEmail.IsBodyHtml = true ;
verificationEmail.Priority = MailPriority.Normal;

smtp.Send(verificationEmail);

email.Dispose();
verificationEmail.Dispose();
ViewData [ 消息] = Su mensaje ha sido enviado satisffactoriamente;
}
catch (例外)
{


I am just trying to generate an email using C#, however, I think I am using the wrong SMTP server, as Gmail times out for some reason. Is there some security configuration required by Google Mail on the From address, or some authentication mechanism that I need to go through, since this is obviously a 'spam' email example?

What would you suggest?

try
           {
               MailMessage m = new MailMessage();
               m.Subject = "test";
               m.From = new MailAddress("president@usa.gov");
               m.To.Add("camilleri.jon@gmail.com");
               SmtpClient smtp = new SmtpClient("smtp.gmail.com");
               smtp.Send(m);
           }
           catch (Exception ex) { Console.WriteLine(ex.Source); }

解决方案

Having a mail-server address doesn't mean you can use it.

Usually, you need to be authenticated in some manner, perhaps simply making the query from it's domain. Since you're not making the request from the appropriate location (some part of google) you are rejected by the server.

As an experiment, switch the mail server to the server for they system where your client is authenticated. This may work.


I recently developed a code as part of a contact page in a website which needed to send email here is the code.

var sender = contact.Email;

           var email = new MailMessage();
           email.To.Add(new MailAddress("arnaldo.skywalker@caudal.cu"));
           email.From = new MailAddress("arnaldo@caudal.cu");
           email.Subject = form["Tipo de contacto"] + " de " + sender;
           email.Body = contact.Message;
           email.IsBodyHtml = true;
           email.Priority = MailPriority.Normal;

           var smtp = new SmtpClient
                          {
                              Host = "192.168.145.209",
                              Port = 25,
                              EnableSsl = false,
                              UseDefaultCredentials = false,
                              Credentials = new NetworkCredential("arnaldo@caudal.cu", "lade


23") }; try { smtp.Send(email); var verificationEmail = new MailMessage(); verificationEmail.To.Add(new MailAddress(sender)); verificationEmail.From = new MailAddress("arnaldo@caudal.cu"); verificationEmail.Subject = "Su " + form["Tipo de contacto"] + " será atendida " + sender; verificationEmail.Body = "Atenderemos su " + form["Tipo de contacto"] + " a la mayor brevedad posible"; verificationEmail.IsBodyHtml = true; verificationEmail.Priority = MailPriority.Normal; smtp.Send(verificationEmail); email.Dispose(); verificationEmail.Dispose(); ViewData["Message"] = "Su mensaje ha sido enviado satisfactoriamente"; } catch (Exception) {


这篇关于Sendmail使用SMTP服务器...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆