Click to See Complete Forum and Search --> : Can send email internally, but not externally?? Also font question???
skake01
April 22nd, 2009, 08:57 AM
Hello,
I am able to send an email internally on my network but not to any of my outside customers. How do I do this? Do I have to get the SMTP server of every one of my customers?
In my code below, I can send the email to myself on my network at SKAKE01@MYEMAILADDRESS.net, but the email does not get sent to my external customer at OUTSIDE_CUSTOMER@yahoo.com. How do I do this?
Also, is there a way to change the font and color in the message body?
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;
namespace email
{
class Program
{
static void Main(string[] args)
{
try
{
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("SKAKE01@MYEMAILADDRESS.net");
message.To.Add("OUTSIDE_CUSTOMER@yahoo.com");
message.Subject = "This is the Subject line";
message.From = new System.Net.Mail.MailAddress("SKAKE01@MYEMAILADDRESS.net");
message.Body = "This is the test message body";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("SKAKE01.***.***.***");
smtp.Send(message);
}
catch (Exception ex)
{
Console.WriteLine("There was an error when attempting to send the e-mail!", "Error", ex.ToString());
}
}
}
}
chenw040
April 22nd, 2009, 11:22 AM
Try:
MailMessage mail = new MailMessage();
mail.To.Add(toEmail);
mail.From = new MailAddress(fromEmail);
mail.Subject = "Subject";
mail.Body = "Body";
SmtpClient smtpClient = new SmtpClient("localhost");
smtpClient.Send(mail);
mail.Dispose();
skake01
April 22nd, 2009, 11:37 AM
Try:
MailMessage mail = new MailMessage();
mail.To.Add(toEmail);
mail.From = new MailAddress(fromEmail);
mail.Subject = "Subject";
mail.Body = "Body";
SmtpClient smtpClient = new SmtpClient("localhost");
smtpClient.Send(mail);
mail.Dispose();
didn't work, it ran into my exception.
Shuja Ali
April 22nd, 2009, 02:39 PM
My first question would be, does your SMTP allow you to send emails to outside world? What happens when you try to send email to the same address form your regular mail client (Outlook, Lotus Notes, etc). To change the color and font of the body, you should use HTMLBody. You can create your body as HTML (using the tags you can change the color, font, etc) and then set that HTML to HTMLBody property of the mailmessage.
skake01
April 22nd, 2009, 03:25 PM
My first question would be, does your SMTP allow you to send emails to outside world? What happens when you try to send email to the same address form your regular mail client (Outlook, Lotus Notes, etc). To change the color and font of the body, you should use HTMLBody. You can create your body as HTML (using the tags you can change the color, font, etc) and then set that HTML to HTMLBody property of the mailmessage.
I can send emails to those addresses from my email. Does it matter that it's a Microsoft Exchange server?
Shuja Ali
April 22nd, 2009, 03:30 PM
No it doesn't matter whether it is exchange server or anything else. As long as you are able to send email form Outlook, you should be able to send email from your code too.
Does your code throw any exception or is it simply executing, but the mail is not reaching the customer? Try checking with your Exchange admins whether there is anything getting queued on the server.
sotoasty
April 22nd, 2009, 03:56 PM
Most e-mail servers will not allow you to send an e-mail to an external address unless you are authenticated. If they did that, which many e-mail servers used to, then spammers would have an easy way to send their mail. SMTP servers will accept mail for anyone that is in your domain. That is how e-mail servers work. You need to be logged in to send an e-mail out of your servers domain.
That is why an e-mail sent to an internal address works, but one to an external address fails.
ETA:
Try adding this line.
smtp.UseDefaulCredentials = true;
If you are then logged into an ADS domain and your exchange server is part of that, it will use the current logged on users credentials to send the e-mail.
escap3
April 24th, 2009, 05:32 AM
should you use your personal smtp server for sending mail to others !?
if your answer is no, you can use a free SMTP server like smtp.gmail.com .
skake01
April 24th, 2009, 09:51 AM
Most e-mail servers will not allow you to send an e-mail to an external address unless you are authenticated. If they did that, which many e-mail servers used to, then spammers would have an easy way to send their mail. SMTP servers will accept mail for anyone that is in your domain. That is how e-mail servers work. You need to be logged in to send an e-mail out of your servers domain.
That is why an e-mail sent to an internal address works, but one to an external address fails.
ETA:
Try adding this line.
smtp.UseDefaulCredentials = true;
If you are then logged into an ADS domain and your exchange server is part of that, it will use the current logged on users credentials to send the e-mail.
thank you this worked.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.