Sending E-mail in C#?
I am trying to send mail but this code raise error "Sending failed"
MailMessage MailMesaji = new MailMessage();
MailMesaji.Subject = "subject";
MailMesaji.Body = "mail body";
//MailMesaji.BodyEncoding = Encoding.GetEncoding("Windows-1254"); // Turkish Character Encoding
Mai开发者_如何转开发lAddress mdrom = new MailAddress("amit.pandey@verydindai.com");
MailMesaji.From = mdrom;
MailMesaji.To.Add(new MailAddress("govind@verydindai.com"));
System.Net.Mail.SmtpClient Smtp = new SmtpClient();
Smtp.Host = "mail.verydindai.com"; // for example gmail smtp server
Smtp.EnableSsl = true;
Smtp.Port = 465;
Smtp.Credentials = new System.Net.NetworkCredential("amit.pandey", "1234567");
Smtp.Send(MailMesaji);
plz tell me solution? and if you have another solution tell me?
Doesn't gmail use a different port for smtp then the default 25?
http://mail.google.com/support/bin/answer.py?hl=en&answer=13287
I am write down a console application please try with this sample. with your credentials To address,From Address,Password,Body text
using System;
using System.Text;
using System.Net.Mail;
using System.Net;
namespace TestingConsole
{
class Program
{
static void Main(string[] args)
{
try
{
string to = "to@domain.com";
string from = "from@gmail.com";
string from_pwd = "mypassword";
string subject = "Sample Mail testing";
string body = "Wow this is testing body";
MailMessage mM = new MailMessage();
mM.From = new MailAddress(from);
mM.To.Add(to);
mM.Subject = subject;
mM.Body = body;
mM.IsBodyHtml = false;
mM.Priority = MailPriority.High;
SmtpClient sC = new SmtpClient("smtp.gmail.com");
sC.Port = 587;
sC.Credentials = new NetworkCredential(from, from_pwd);
sC.EnableSsl = true;
sC.Send(mM);
}
catch (Exception e)
{
Console.WriteLine(e.Message + " " + e.StackTrace);
}
}
}
}
string to = "";
string from = "";
string from_pwd = "";
MailMessage mM = new MailMessage();
mM.From = new MailAddress(from);
mM.To.Add(to);
mM.Subject = subject;
mM.Body = body;
mM.IsBodyHtml = true;
mM.Priority = MailPriority.High;
SmtpClient sC = new SmtpClient("smtp.gmail.com");
sC.Port = 587;
sC.Credentials = new NetworkCredential(from, from_pwd );
sC.EnableSsl = true;
sC.Send(mM);
You might need to change the port you're connecting to, I think for google it should be 465 or 587 if SSL is enabled.
Also check if you have some AntiVirus software that might be interfering. It's quite common for AV software to stop custom software sending email. There might also be some firewall that don't let you through on the required port.
精彩评论