Email not reaching a specific email domain from php or C# - c#

I am currently using an Office 365 account to send email from various websites. I have implemented an smtp client in both php and C# to send the mail. I use GoDaddy and Rackspace to hosts my sites.
The mail reaches most address without issue, however, I have a business domain through Google, which ends with .co, and emails do not make it to my inbox there.
Here are the settings for the PHPMailer client:
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPSecure = "tls";
$mail->Host = 'smtp.office365.com';
$mail->SMTPAuth = true;
$mail->Username = '<myuser>';
$mail->Password = '<mypassword>';
$mail->Port = 587;
$mail->setFrom('noreply#<mymaildomain>.com', 'MyMail');
The settings send email find to yahoo, gmail, etc. However, when I try to send it to my .co email address, the client indicates the mail was sent, but it never shows up in the inbox.
I am wondering if it is an issue with a domain in Google or if the .co is the problem. Is there any special setting I need to make on the client for .co addresses?
UPDATE
I changed phpmailer to simply use php's mail function. The mail was sent through to my .co domain, but I still have no idea why it will not go through when an authenticated SMTP user sends it. I can go into my Office 365 account and send email to the .co address without issue. I just cannot push it from the server. My host server does not contain the smtp server.

Related

Sending mail from office365 account C# mail headers

I can send mail with a valid Office365 account using my C# web application to a list of opt-in addresses. So it is our own data source with our customers in it. The problem is that it is probably not received by our customers. I have send a mail from the info account to my own office365 account and pasted the headers in mxtoolbox and got a message that my local pc is blacklisted. even when it is using the smtp of office365. We have dkim enabled and spf in the dns. What else should I do to troubleshoot this?
Here is my simple C# code for sending the mail (which works, but might needs additional anti-spam stuff?)
SmtpClient sc = new SmtpClient();
sc.Host = "smtp.office365.com";
sc.Credentials = new System.Net.NetworkCredential(SmtpUsername, SmtpPassword);
sc.Port = 587;
sc.EnableSsl = true;
Should I add my home IP and from the office to the SPF dns entry, even when I am using the smtp of office365?
this is the value for Authentication-Results
dkim=none (message not signed) header.d=none;ouroffice365domain.com; dmarc=none action=none
Is that the cause for getting on the blacklist? Please note that I am not trying to send spam. It is a valid data source where people opted in for. We are just migrated to office365 and need to send a mailing to our customers from our custom web application. We are aware of the limitations (10k per day) and 1 mail every 2 sec.
edit will change this: https://stackoverflow.com/a/23409351/169714 because I just used the mail address and not the first and last name of the customer.
Not having DKIM setup is not going to get you blackisted, having it set up improperly can. Your HOME PC should have nothing to do with SPF, it's the lasting sending IP which should be OFFICE 365 IP. Did you validate your DKIM and SPF by sending an email to mailtest#unlocktheinbox.com or check-auth#verifier.port25.com?
I also don't think your LOCAL PC is blacklisted, it's the IP of your INTERNET Provider that is blacklisted. Unless you have a static IP it will change.

Sending email via exchange server issue. (system.net.mail vs microsoft.exchange.webservices)

I am developing a web application for my company. Part of it requires the internal user to fill out a form, and send an email on this user's behalf. It is all within the company. I searched and found two possible routes old system.net.mail and a more recent microsoft.exchange.webservices, but seems our exchange server requires credentials. I can only get the user's login and his email address login+"#company.com". How can i get this done?
Below are the codes i used smtp (system.net.mail), but it doesnt work.
string[] username =System.Security.Principal.WindowsIdentity.GetCurrent().Name.Split('\\');
string email = username[1] + "#company.com";
MailAddress from = new MailAddress(email);
MailAddress to = new MailAddress("someone#company.com");
MailMessage message = new MailMessage(from, to);
message.Subject = "testmail";
message.Body = "<h>testmail</h>";
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(message);
SmtpClient requires that you either specify the SMTP server directly, or that you have the right application/machine configuration settings for it to detect the server automatically. Your code is choosing the second option implicitly, and I suspect you don't have the right settings in app/machine config. Exchange does NOT support SMTP in its default configuration, afaik, so unless someone familiar with your Exchange server knows SMTP is configured and can give you the right address, SmtpClient is probably out.
Exchange Web Services (aka EWS) is probably your better answer, but it's not really a good one. In order to use exchange web services, you will need one of:
1) The domain, username, and password of the user so that you can pass the right NetworkCredential to EWS. In your case, this would probably mean the user has to enter their password into your form, which may break your requirements.
2) The user that the process is running as (in a web application, the application pool identity for IIS) has to have permissions to send mail as the user in question.
3) If you can use ASP.NET authentication to impersonate the user (this would only be a good approach in a LAN application), then you can effectively fall back to option (2), because now you will be talking to EWS as the user, who obviously will have permission to send mail from their own address.
As you can see, the right approach depends greatly on your Exchange/Active Directory/LAN setup.

What is SMTP Server Address and how to get SMTP Server Address?

i am trying to send email from c# windows application and i need SMTP Server Address to send email but i don't know about SMTP Server Address, what is SMTP Server Address, how to get SMTP Server Address and how to use it.
this is the code:
System.Web.Mail.MailMessage message=new System.Web.Mail.MailMessage();
message.From="from e-mail";
message.To="to e-mail";
message.Subject="Message Subject";
message.Body="Message Body";
System.Web.Mail.SmtpMail.SmtpServer="SMTP Server Address";
System.Web.Mail.SmtpMail.Send(message);
What Mail Server are you trying to use??? usually you can just google SMTP or POP3 or whatever protocal your looking for and it will give you the port, server and all the extra information you need to connect to it.
For example:
http://support.google.com/mail/bin/answer.py?hl=en&answer=13287
First, the System.Web.Mail namespace utilities are marked as 'obsolete' and should not be used. Instead, you should use System.Net. In that namespace there is a 'MailMessage' and an 'SmtpClient' class that will do the job you are trying to do.
Next, an SMTP server is a process that runs on a computer, which, when connected to the inetrnet, can listen for, and respond to, incoming requests which use a particular protocol on a particular port. You can think of an SMTP server as the machine at the post office that sorts and routes the mail to the appropriate mailbox..
An SMTP server has an address, just like everything else on the internet that needs to communicate with anything else. The address is used to send your mail message to the right machine, on the right communication channel. you could think of it as its phone number, and your mail message a text that will be sent to it.
Next, the address you are looking for, last time I checked, was: smtp.gmail.com.
So, considering that you need to stop using System.Web.Mail, and considering that your address may be smtp.gmail.com, here is what your code should look like:
// setup mail message
MailMessage message = new MailMessage();
message.From = new MailAddress("from e-mail");
message.To.Add(new MailAddress("to e-mail"));
message.Subject = "Message Subject";
message.Body = "Message Body";
// setup mail client
SmtpClient mailClient = new SmtpClient("smtp.gmail.com");
mailClient.Credentials = new NetworkCredential("youraccount#gmail.com", "yourGmailPassword");
// send message
mailClient.Send(message);
Also, here is a decent looking article on using gmail as your smtp server:
How to use Gmail as your SMTP server
Also, if gmail does not work for you, you can use the smtp server of your internet provider. They will usually have their smtp address lurking on their website somewhere to be helpful to customers who want to setup their email program. You can also look in Outlook under account settings if you cannot find it somewhere else, if you use anything besides gmail, you should find one there.
Lastly, keep in mind, email cannot be sent without using an smtp server which is willing to receive and dispatch your maill message. In general this is something like gmail, or the smtp server of your internet provider, and the address will normally be: smtp.providername.com. However, gmail, for example, requires your account credentials for the smtp server to allow your message to be received and dispatched.

C# SMTP mail sending usually fails due to lack of credentials?

It seems that when you use SmtpClient class and MailMessage to send emails, everything works fine. And it does send it. However, some servers, such as your business Exchange Server or Gmail.com or whatever services, sometimes reject these emails (because they could be phishing sites or spam sites?)
I'm using this and a lot of places reject the email I believe:
SmtpClient smtp = new SmtpClient
{
Host = smtpClient,
Timeout = 40000, // 40 seconds
DeliveryMethod = SmtpDeliveryMethod.Network
};
How do you work around this? Do you have to use login credentials to some recognized / white-listed server so that it is authorized and trusted email?
I could use something like GMAIL authentication, but my server should be allowed to send emails, it shouldn't have to rely on gmail.
Long ago there were many servers on the Internet that provided the service delivery of e-mail without asking too many questions about who was using the service.
Then came the SPAMMERS!.
A server that was sending mail freely around the world was no longer a benefactor of the internet, but a problem.
Nowadays it is increasingly difficult to find a server that sends mail on the Internet without asking for credentials.
Your e-mail server (smtp.yourbusiness.com or whatever you want) does not trust you.
When you ask it to send an email for you, it wants to know who you are.
SmtpClient smtp = new SmtpClient
smtp.Host = "smtp.yourbusiness.com";
NetworkCredential credentials = new NetworkCredential("your_user_name_on_smtpserver", "your_password_on_smtpserver");
smtp.Credentials = credentials;
are you setting the sender mail address and can your mail server be resolved by reverse dns lookup? Some spam filters distrust mail servers they can't reverse lookup. If you for instance make your mail server send mails using a bogus or foreign mail domain, spam filters will probably pick this up and filter your mail. If you have set up a SPF record for your domain and your sending mail server isn't in that record, mails from that server will also often be filtered by spam filters. Another reason could be an IP address from a range known to be dynamically assigned by internet providers. Mail servers sending from these address ranges are mostly spam bots and are therefore often also filtered.
To send GMail you need to specify a number of settings - yes you'll need to use authentication (GMail wouldn't open up their relay to everyone, or they'd get used for spamming).
If I recall correctly you need to send on TCP port 587, enable SSL, host to mail.google.com and provide a username and password on your SmtpClient to get Gmail to actually send it - neglecting one of those usually generates an email back from them telling you what you've forgotten.
Edit: Just to clarify on the username and password bit; you'd need to create a new NetworkCredential with the username and password for your GMail account, and set the Credentials property of your SmtpClient to that.
If i interpret your question correctly: the messages are sent our from your server, but they are trapped in the spamfilters at the receiving end?
If this is the problem, it has nothing to to with the way you are sending the messages but much more with the content of your message and the characteristics of your server. So it does not matter what credentials you use or if you send it with SmtpClient or any other class. Moving to Gmail does not help and Gmail has a limit to the number of messages you can send.
Spam filters like spam assassin use rules. Match too many: your message is considered spam.
Have a look here for an example:
http://spamassassin.apache.org/tests_3_3_x.html
So make sure your message does not get too high a score and it will go trough.

change sender address when sending mail through gmail in c#

I have used the following code to send mail from my web application using a gmail account. My question is, can i change the sender address to another address other than original sender(gmail) address?
My code is as follows:
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("sample#gmail.com", "*******");
Whatever i do is useless as i always receive mail from sample#gmail.com. Is it possible to change it?
I have changed to
mail.From = new System.Net.Mail.MailAddress("sample#yahoo.com"); but i received the mail with the from address sample#gmail.com and not from the new "From" address. I think gmail smtp overwrites the from address with the original credential.
This is the solution:
use the codes above to set mail.From = new MailAddress(address, display name)
in Gmail, go to Mail Settings >> Accounts and Import.
Add the email account you will use as sender in "Send Mail As". (tick as Alias)
This works for me
Gmail doesn't allow you to change the FROM to something different than your gmail account.
It doesn't matter what you use, they over-write it, before they relay it on. This prevent spamming/spoofing.
Yes just use the From property of the MailMessage
eg.
mail.From = "newemail#email.com";
EDIT: Also, see this post for more detailed info on how to emails via gmail in C#
Sending email in .NET through Gmail
EDIT: Although this works for mail in general, it appears this won't work for gmail as google overwrite it before its sent (see #Dave wanta's answer)
If you have a limited number of senders you can do as #philip suggested. For instance you may have customerservice#example.com, simon#example.com and philip#example.com or even alias#example.com. As long as they are approved senders on the actual gmail.com website you can send from them.
Gmail.com : Sending mail from a different address
If you are expecting to send from an arbitrary user (such as a customer service form on a website where the user enters their email and you don't want them emailing you directly) about the best you can do is this :
msg.ReplyToList.Add(new System.Net.Mail.MailAddress(email, friendlyName));
If you're in a controlled environment this works great, but please note that I've seen some email clients send to the from address even when reply-to is specified (I don't know which).
Check #56 and #58. They might be relevant to what you want to do
https://code.google.com/p/google-apps-script-issues/issues/detail?id=172

Categories

Resources