Amok Khan
Amok Khan

Reputation: 49

c# send mail in gmail not received

I have a problem to received mails in gmail!

I tested it with outlook, yahoo, gmx and at all I have got the mail from my tool but not in my gmail. Anyone has an idea?

mtpClient clientxy = new SmtpClient("smtp.mydomain.com");
clientxy.Port = 25;
clientxy.EnableSsl = false;
clientxy.Timeout = 3600;
clientxy.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
clientxy.UseDefaultCredentials = false;
NetworkCredential Credentials = new NetworkCredential("[email protected]", "PWD");
clientxy.Credentials = Credentials;
MailMessage msg = new MailMessage("[email protected]", text_Email.Text);
msg.BodyEncoding = UTF8Encoding.UTF8;
msg.Subject = "Subject";

string htmlBody;
msg.IsBodyHtml = true;
htmlBody = "<html>---html code";
msg.Body = htmlBody;

Attachment inline = new Attachment(@"file.xml");
inline.ContentDisposition.Inline = true;
msg.Attachments.Add(inline);
clientxy.Send(msg);

here php code this work

$mail = new PHPMailer();
$mail->isSMTP();
//$mail->SMTPDebug = 2;
$mail->SMTPAuth = TRUE;
$mail->Host     = "smtp.mydomain.com";
$mail->Port     = 25;
$mail->Username = "[email protected]";
$mail->Password = "";
$mail->SetFrom("[email protected]", "");
$mail->Subject  = utf8_decode("sub");
$mail->AltBody  = utf8_decode("body");
$mail->MsgHTML(utf8_decode($msg));
$mail->AddAddress("to");
$mail->AddBCC("[email protected]");

I think the code is OK But I don't know what the problem is. ONLY in gmail I never received it. Thanks!

Upvotes: 3

Views: 1570

Answers (3)

Amok Khan
Amok Khan

Reputation: 49

I found the problem!

I dont know why gmail dont receive emails from smtpclient but i install a nuget with an other smtp function and this works !

Thanks all for help!!

Upvotes: 1

jjj
jjj

Reputation: 1154

following setting should work

clientxy.Port = 587;
clientxy.EnableSsl = true;

Another point is

You must change your password at least once. And try to use a secure level password (do not use the same user as password, 123456, etc.)

Upvotes: 0

klashar
klashar

Reputation: 2563

Please check Gmail settings. It is not allowed to send via 25 port.

Try this settings instead

clientxy.Port = 465;
clientxy.EnableSsl = true;

Upvotes: 2

Related Questions