sending mails
-
I managed to send emails but if I change client.Host = "smtp.gmail.com" to client.Host = "smtp.hotmail.com" or client.Host = "smtp.yahoo.com"; it does that works only with gmail namespace mailing { public partial class SendMail : Form { public SmtpClient client = new SmtpClient(); public MailMessage msg = new MailMessage(); public NetworkCredential smtpCreds = new NetworkCredential("aa@gmail.com", "aaa"); public SendMail() { InitializeComponent(); } public void SendMails(string sendFrom, string sendTo, string subject, string body) { try { client.Host = "smtp.gmail.com"; client.Port = 587; client.UseDefaultCredentials = false; client.Credentials = smtpCreds; client.EnableSsl = true; MailAddress to = new MailAddress(sendTo); MailAddress from = new MailAddress(sendFrom); msg.Subject = txtSubject.Text; msg.Body ="<html><body>"+txtMail.Text+"
</body></html>"; msg.IsBodyHtml = true; msg.From = new System.Net.Mail.MailAddress(txtFrom.Text); msg.To.Add(txtTo.Text); // Attachment piece_joint = new Attachment(@"txtpiece.Text", MediaTypeNames.Application.Pdf); AlternateView alternate = AlternateView.CreateAlternateViewFromString(msg.Body,null,MediaTypeNames.Text.Html); LinkedResource img = new LinkedResource(@txtpiece.Text, MediaTypeNames.Image.Jpeg); img.ContentId = "idimg"; alternate.LinkedResources.Add(img); msg.AlternateViews.Add(alternate); msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess | DeliveryNotificationOptions.OnFailure; client.SendCompleted += new SendCompletedEventHandler(smtp_sendcompleted); client.SendAsync(msg,null); } catch (Exception ex) { MessageBox.Show("Failed to send this mail" +ex.Message); } } static void smtp_sendcompleted(object sender,AsyncCompletedEventArgs e) { if (e.Error != n
-
I managed to send emails but if I change client.Host = "smtp.gmail.com" to client.Host = "smtp.hotmail.com" or client.Host = "smtp.yahoo.com"; it does that works only with gmail namespace mailing { public partial class SendMail : Form { public SmtpClient client = new SmtpClient(); public MailMessage msg = new MailMessage(); public NetworkCredential smtpCreds = new NetworkCredential("aa@gmail.com", "aaa"); public SendMail() { InitializeComponent(); } public void SendMails(string sendFrom, string sendTo, string subject, string body) { try { client.Host = "smtp.gmail.com"; client.Port = 587; client.UseDefaultCredentials = false; client.Credentials = smtpCreds; client.EnableSsl = true; MailAddress to = new MailAddress(sendTo); MailAddress from = new MailAddress(sendFrom); msg.Subject = txtSubject.Text; msg.Body ="<html><body>"+txtMail.Text+"
</body></html>"; msg.IsBodyHtml = true; msg.From = new System.Net.Mail.MailAddress(txtFrom.Text); msg.To.Add(txtTo.Text); // Attachment piece_joint = new Attachment(@"txtpiece.Text", MediaTypeNames.Application.Pdf); AlternateView alternate = AlternateView.CreateAlternateViewFromString(msg.Body,null,MediaTypeNames.Text.Html); LinkedResource img = new LinkedResource(@txtpiece.Text, MediaTypeNames.Image.Jpeg); img.ContentId = "idimg"; alternate.LinkedResources.Add(img); msg.AlternateViews.Add(alternate); msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess | DeliveryNotificationOptions.OnFailure; client.SendCompleted += new SendCompletedEventHandler(smtp_sendcompleted); client.SendAsync(msg,null); } catch (Exception ex) { MessageBox.Show("Failed to send this mail" +ex.Message); } } static void smtp_sendcompleted(object sender,AsyncCompletedEventArgs e) { if (e.Error != n
You have to make sure the port your using matches the specification of those other hosts. Google uses 587 for secured communication to the SMTP server. Hotmail and Yahoo will probably not use the same port numbers. Check with them.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
I managed to send emails but if I change client.Host = "smtp.gmail.com" to client.Host = "smtp.hotmail.com" or client.Host = "smtp.yahoo.com"; it does that works only with gmail namespace mailing { public partial class SendMail : Form { public SmtpClient client = new SmtpClient(); public MailMessage msg = new MailMessage(); public NetworkCredential smtpCreds = new NetworkCredential("aa@gmail.com", "aaa"); public SendMail() { InitializeComponent(); } public void SendMails(string sendFrom, string sendTo, string subject, string body) { try { client.Host = "smtp.gmail.com"; client.Port = 587; client.UseDefaultCredentials = false; client.Credentials = smtpCreds; client.EnableSsl = true; MailAddress to = new MailAddress(sendTo); MailAddress from = new MailAddress(sendFrom); msg.Subject = txtSubject.Text; msg.Body ="<html><body>"+txtMail.Text+"
</body></html>"; msg.IsBodyHtml = true; msg.From = new System.Net.Mail.MailAddress(txtFrom.Text); msg.To.Add(txtTo.Text); // Attachment piece_joint = new Attachment(@"txtpiece.Text", MediaTypeNames.Application.Pdf); AlternateView alternate = AlternateView.CreateAlternateViewFromString(msg.Body,null,MediaTypeNames.Text.Html); LinkedResource img = new LinkedResource(@txtpiece.Text, MediaTypeNames.Image.Jpeg); img.ContentId = "idimg"; alternate.LinkedResources.Add(img); msg.AlternateViews.Add(alternate); msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess | DeliveryNotificationOptions.OnFailure; client.SendCompleted += new SendCompletedEventHandler(smtp_sendcompleted); client.SendAsync(msg,null); } catch (Exception ex) { MessageBox.Show("Failed to send this mail" +ex.Message); } } static void smtp_sendcompleted(object sender,AsyncCompletedEventArgs e) { if (e.Error != n
Most SMTP servers require you to be an authorised user (i.e. if I use Clara.net as my ISP, I can use the smtp.clara.net relay, but if you don't, you can't). Gmail allows you to use your Gmail account details to log into SMTP; I'm not sure if Hotmail and Yahoo do something similar but if so, at the minimum, you will have to change the credentials you're trying to use.
-
You have to make sure the port your using matches the specification of those other hosts. Google uses 587 for secured communication to the SMTP server. Hotmail and Yahoo will probably not use the same port numbers. Check with them.
A guide to posting questions on CodeProject[^]
Dave KreskowiakDave Kreskowiak wrote:
Hotmail and Yahoo will probably not use the same port numbers
Port 587 is a standard for SMTP servers (similar to port 25), usually referred to as the 'submission' port. It's set aside for authenticated users to submit messages to the e-mail service. It typically needs encryption, but I don't believe that's a requirement of the standard. https://www.ietf.org/rfc/rfc2476.txt[^]
-
I managed to send emails but if I change client.Host = "smtp.gmail.com" to client.Host = "smtp.hotmail.com" or client.Host = "smtp.yahoo.com"; it does that works only with gmail namespace mailing { public partial class SendMail : Form { public SmtpClient client = new SmtpClient(); public MailMessage msg = new MailMessage(); public NetworkCredential smtpCreds = new NetworkCredential("aa@gmail.com", "aaa"); public SendMail() { InitializeComponent(); } public void SendMails(string sendFrom, string sendTo, string subject, string body) { try { client.Host = "smtp.gmail.com"; client.Port = 587; client.UseDefaultCredentials = false; client.Credentials = smtpCreds; client.EnableSsl = true; MailAddress to = new MailAddress(sendTo); MailAddress from = new MailAddress(sendFrom); msg.Subject = txtSubject.Text; msg.Body ="<html><body>"+txtMail.Text+"
</body></html>"; msg.IsBodyHtml = true; msg.From = new System.Net.Mail.MailAddress(txtFrom.Text); msg.To.Add(txtTo.Text); // Attachment piece_joint = new Attachment(@"txtpiece.Text", MediaTypeNames.Application.Pdf); AlternateView alternate = AlternateView.CreateAlternateViewFromString(msg.Body,null,MediaTypeNames.Text.Html); LinkedResource img = new LinkedResource(@txtpiece.Text, MediaTypeNames.Image.Jpeg); img.ContentId = "idimg"; alternate.LinkedResources.Add(img); msg.AlternateViews.Add(alternate); msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess | DeliveryNotificationOptions.OnFailure; client.SendCompleted += new SendCompletedEventHandler(smtp_sendcompleted); client.SendAsync(msg,null); } catch (Exception ex) { MessageBox.Show("Failed to send this mail" +ex.Message); } } static void smtp_sendcompleted(object sender,AsyncCompletedEventArgs e) { if (e.Error != n
Hi, You can refer email sending code snippet in below link Send email using htomail Smtp used for HOTMail is SMTP: smtp.live.com port: 25
-
I managed to send emails but if I change client.Host = "smtp.gmail.com" to client.Host = "smtp.hotmail.com" or client.Host = "smtp.yahoo.com"; it does that works only with gmail namespace mailing { public partial class SendMail : Form { public SmtpClient client = new SmtpClient(); public MailMessage msg = new MailMessage(); public NetworkCredential smtpCreds = new NetworkCredential("aa@gmail.com", "aaa"); public SendMail() { InitializeComponent(); } public void SendMails(string sendFrom, string sendTo, string subject, string body) { try { client.Host = "smtp.gmail.com"; client.Port = 587; client.UseDefaultCredentials = false; client.Credentials = smtpCreds; client.EnableSsl = true; MailAddress to = new MailAddress(sendTo); MailAddress from = new MailAddress(sendFrom); msg.Subject = txtSubject.Text; msg.Body ="<html><body>"+txtMail.Text+"
</body></html>"; msg.IsBodyHtml = true; msg.From = new System.Net.Mail.MailAddress(txtFrom.Text); msg.To.Add(txtTo.Text); // Attachment piece_joint = new Attachment(@"txtpiece.Text", MediaTypeNames.Application.Pdf); AlternateView alternate = AlternateView.CreateAlternateViewFromString(msg.Body,null,MediaTypeNames.Text.Html); LinkedResource img = new LinkedResource(@txtpiece.Text, MediaTypeNames.Image.Jpeg); img.ContentId = "idimg"; alternate.LinkedResources.Add(img); msg.AlternateViews.Add(alternate); msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess | DeliveryNotificationOptions.OnFailure; client.SendCompleted += new SendCompletedEventHandler(smtp_sendcompleted); client.SendAsync(msg,null); } catch (Exception ex) { MessageBox.Show("Failed to send this mail" +ex.Message); } } static void smtp_sendcompleted(object sender,AsyncCompletedEventArgs e) { if (e.Error != n
If you have a search on Google you may find some free to use public smtp hosts. I did use a one a few years abck for a project - don't recall the name but worth a try.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me
-
Dave Kreskowiak wrote:
Hotmail and Yahoo will probably not use the same port numbers
Port 587 is a standard for SMTP servers (similar to port 25), usually referred to as the 'submission' port. It's set aside for authenticated users to submit messages to the e-mail service. It typically needs encryption, but I don't believe that's a requirement of the standard. https://www.ietf.org/rfc/rfc2476.txt[^]
It may be standard, but that doesn't mean people have to use it. Yahoo uses different ports, depending on which service level your have. I think, last I checked anyway, one is using port 995 and the other 465???
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
It may be standard, but that doesn't mean people have to use it. Yahoo uses different ports, depending on which service level your have. I think, last I checked anyway, one is using port 995 and the other 465???
A guide to posting questions on CodeProject[^]
Dave KreskowiakTrue, standards can be ignored but it's worth pointing out that the ports listed weren't just arbitrarily chosen by the service provider. 995 is used for encrypting the POP3 protocol (POP3S, another standard :-D ). Port 465 is an old remnant from Exchange's method of encryption. It's become common due to Outlook/Microsoft's support of Exchange over the Submission port standard in their mail clients. These days, both protocols are supported in Outlook. One other note about 465 is that it will break using System.Net.Mail.SmtpClient due to how the encryption was implemented. See the remarks section at http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.enablessl.aspx[^] for the details.
-
True, standards can be ignored but it's worth pointing out that the ports listed weren't just arbitrarily chosen by the service provider. 995 is used for encrypting the POP3 protocol (POP3S, another standard :-D ). Port 465 is an old remnant from Exchange's method of encryption. It's become common due to Outlook/Microsoft's support of Exchange over the Submission port standard in their mail clients. These days, both protocols are supported in Outlook. One other note about 465 is that it will break using System.Net.Mail.SmtpClient due to how the encryption was implemented. See the remarks section at http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.enablessl.aspx[^] for the details.
Yeah, but the entire point was he needs to check with each provider to make sure the port settings are correct and hes using the correct connection options.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Hi, You can refer email sending code snippet in below link Send email using htomail Smtp used for HOTMail is SMTP: smtp.live.com port: 25
I will try thank you, thank you
-
Most SMTP servers require you to be an authorised user (i.e. if I use Clara.net as my ISP, I can use the smtp.clara.net relay, but if you don't, you can't). Gmail allows you to use your Gmail account details to log into SMTP; I'm not sure if Hotmail and Yahoo do something similar but if so, at the minimum, you will have to change the credentials you're trying to use.
yes I have already tested it does not work with yahoo and hotmail: Exception: authetification required
-
yes I have already tested it does not work with yahoo and hotmail: Exception: authetification required
So are you using the correct username and password with Yahoo and Hotmail?? I'm gussing your GMail account and password are not going to work with those providers.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
So are you using the correct username and password with Yahoo and Hotmail?? I'm gussing your GMail account and password are not going to work with those providers.
A guide to posting questions on CodeProject[^]
Dave KreskowiakI'm sorry I misunderstood, and I will explain when I send a mail and the sender is a user with a gmail account it works, I sent mail to Yahho and hotmail without any problems but if I Chenge sender then there is the problem
-
I managed to send emails but if I change client.Host = "smtp.gmail.com" to client.Host = "smtp.hotmail.com" or client.Host = "smtp.yahoo.com"; it does that works only with gmail namespace mailing { public partial class SendMail : Form { public SmtpClient client = new SmtpClient(); public MailMessage msg = new MailMessage(); public NetworkCredential smtpCreds = new NetworkCredential("aa@gmail.com", "aaa"); public SendMail() { InitializeComponent(); } public void SendMails(string sendFrom, string sendTo, string subject, string body) { try { client.Host = "smtp.gmail.com"; client.Port = 587; client.UseDefaultCredentials = false; client.Credentials = smtpCreds; client.EnableSsl = true; MailAddress to = new MailAddress(sendTo); MailAddress from = new MailAddress(sendFrom); msg.Subject = txtSubject.Text; msg.Body ="<html><body>"+txtMail.Text+"
</body></html>"; msg.IsBodyHtml = true; msg.From = new System.Net.Mail.MailAddress(txtFrom.Text); msg.To.Add(txtTo.Text); // Attachment piece_joint = new Attachment(@"txtpiece.Text", MediaTypeNames.Application.Pdf); AlternateView alternate = AlternateView.CreateAlternateViewFromString(msg.Body,null,MediaTypeNames.Text.Html); LinkedResource img = new LinkedResource(@txtpiece.Text, MediaTypeNames.Image.Jpeg); img.ContentId = "idimg"; alternate.LinkedResources.Add(img); msg.AlternateViews.Add(alternate); msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess | DeliveryNotificationOptions.OnFailure; client.SendCompleted += new SendCompletedEventHandler(smtp_sendcompleted); client.SendAsync(msg,null); } catch (Exception ex) { MessageBox.Show("Failed to send this mail" +ex.Message); } } static void smtp_sendcompleted(object sender,AsyncCompletedEventArgs e) { if (e.Error != n
Change this line of code:
public NetworkCredential smtpCreds = new NetworkCredential("aa@gmail.com", "aaa");
Note that the credentials are pointing to gmail. You get that when you stare at a passage of code long enough.
"You get that on the big jobs."
-
I'm sorry I misunderstood, and I will explain when I send a mail and the sender is a user with a gmail account it works, I sent mail to Yahho and hotmail without any problems but if I Chenge sender then there is the problem
Yeah, and I'll say it again. The error message says that the username and password you used to login to the SMTP server were not good credentials. Either the username was spelled wrong or that account doesn't exist on that server or the password you specified for that username wasn't correct.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
I managed to send emails but if I change client.Host = "smtp.gmail.com" to client.Host = "smtp.hotmail.com" or client.Host = "smtp.yahoo.com"; it does that works only with gmail namespace mailing { public partial class SendMail : Form { public SmtpClient client = new SmtpClient(); public MailMessage msg = new MailMessage(); public NetworkCredential smtpCreds = new NetworkCredential("aa@gmail.com", "aaa"); public SendMail() { InitializeComponent(); } public void SendMails(string sendFrom, string sendTo, string subject, string body) { try { client.Host = "smtp.gmail.com"; client.Port = 587; client.UseDefaultCredentials = false; client.Credentials = smtpCreds; client.EnableSsl = true; MailAddress to = new MailAddress(sendTo); MailAddress from = new MailAddress(sendFrom); msg.Subject = txtSubject.Text; msg.Body ="<html><body>"+txtMail.Text+"
</body></html>"; msg.IsBodyHtml = true; msg.From = new System.Net.Mail.MailAddress(txtFrom.Text); msg.To.Add(txtTo.Text); // Attachment piece_joint = new Attachment(@"txtpiece.Text", MediaTypeNames.Application.Pdf); AlternateView alternate = AlternateView.CreateAlternateViewFromString(msg.Body,null,MediaTypeNames.Text.Html); LinkedResource img = new LinkedResource(@txtpiece.Text, MediaTypeNames.Image.Jpeg); img.ContentId = "idimg"; alternate.LinkedResources.Add(img); msg.AlternateViews.Add(alternate); msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess | DeliveryNotificationOptions.OnFailure; client.SendCompleted += new SendCompletedEventHandler(smtp_sendcompleted); client.SendAsync(msg,null); } catch (Exception ex) { MessageBox.Show("Failed to send this mail" +ex.Message); } } static void smtp_sendcompleted(object sender,AsyncCompletedEventArgs e) { if (e.Error != n
And of course
John.Doe@hotmail.com
is not allowed to send an email with the sender of the email set toJohn.Doe@gmail.com
. That's not a requirement of the smtp protocol, but a requirement of any sensible provider, oh spammer!