Send mail with not existing mailaccount as sender - c#

I'm currently facing an obscure problem and I hope that someone might know an answer to this.
In the past, my company was working with Delphi 5. Email-sending was handled by a component called TNMSMTP. It's custom for these applications to use fake mail-adresses as an additional source of information. For example, if the service "ReceiveDelivery" on the server sv102 would encounter a problem, the mail adress would be ReceiveDelivery#sv102
I'm rather new here and try to convince management to make the step to .net programming. For that, I need to imitate the above behaviour by using the system.net.mail framework.
However, whenever I try to use a fake mail address I receive the 5.7.1 "Client does not have permissions to send as this sender" exception.
The new Program runs on the same server, under the same user and tries to access the same smtp server as the old delphi programs.
My question is: Can I somehow bypass this, or do I need to get back to Delphi for this to work?

The error you're receiving is from your smtp server, which indicates that you're not authenticating with the server in the same way as before.
Are you sure you've correctly configured the smtp client? You can do so using the smtp configuration element in your .config file or at runtime programmatically.
Also, you could try using the fully qualified domain name (FQDN) of the server. For example the sender email address would be: ReceiveDelivery#sv102.internal.company.com. You can get the FQDN using the following .NET code: How to find FQDN of local machine in C#/.NET ?.

so we finally found the solution to this problem.
It seems that the right to send mails with variable sender adresses is not bound to specific users, but to the server the application is run on.
In my case, the .net development server wasn't in that list. Now that we added it, I can use this functionality.
Thank you guys!

Related

send email via asp.net 3.5

Im looking to send email vi a .net 3.5 form (C#)
Ive seen a few posts elsewhere and got the thing running ok for certain addresses but not for others, eg gmail accounts.
The finished app will have to pick up addresses from a database so Im having to cater for a lot of possibilites.
Im not looking to have my work done for me, just a shove in the right direction would be cool!
thanks
DD
Is it possible the gmail accounts are blocking you as a spammer? If you're sending out a lot of emails, or if there is a configuraiton issue on your server, they may have blacklisted you.
If the emails are going out from your server OK, but not reaching ALL of the recipients but is reaching SOME, then there is likely an issue outside of your direct control. An email goes through several servers in between your server and the enduser's inbox (and that's the case even if the inbox is on google's server for gmail.)
That said, there are things you can do to reduce your likelihood of being blocked/blacklisted.
This is a good place to start: http://www.andreas-kraus.net/blog/tips-for-avoiding-spam-filters-with-systemnetmail/
and then here is where to go from there. (Sorry - it's just a google search, but I gave you the relevant terms, at least.) http://www.google.com/search?q=system.net.mail+blacklist+spammer&rls=com.microsoft:en-us&ie=UTF-8&oe=UTF-8&startIndex=&startPage=1
Finally, here's a very good resource with a cool URL. Perhaps the force will be with you if you learn these ways, young padawan.
http://www.emaildeliveryjedi.com/avoid-spam-filters.php
But getting back to your original question - everything you need to know about how to write code to send an email is covered here: http://www.systemnetmail.com/ It's the same for all versions of .NET from 2.0 on uo through the current 4.0.
And I'm sure you're already aware, but in case you're not, be sure you're familiar with the CAN-SPAM act. http://business.ftc.gov/documents/bus61-can-spam-act-compliance-guide-business
In addition to the great info from David Stratton...If you're certain that the gmail accounts are not receiving your emails, i.e. you've waited for sometime, checked the gmail spam boxes, and you've checked your SMTP server logs to ensure that Google is not sending any particular messages back to your SMTP server, then you may have run into a case of grey-listing / black-listing.
Black-listing can occur when a mail service has decided that the IP address of your mail server is a spamming server. It can happen under different scenarios, shared scenarios can be quite common.
One shared scenario: Let's say you recently acquired a new IP address, but it was recycled by your hosting provider from a prior client of theirs, who was a spammer. There is no guarantee that the IP address would be white-listed.
Another shared scenario: You're sending emails on a shared hosting website, where your SMTP service that you are using is shared with other clients of the SMTP service provider. It may be that one of those clients used the SMTP service maliciously or without following appropriate SPAM rules that gmail abides by.
Your best bet is to contact Google to commence a white-listing process. Providing you follow their requirements, they should eventually unblock emails originating from your service.

Sending Email to a specific address without requiring user to specify their mail server details

Can anyone recommend a simple and reliable method of sending email notifications and possibly log files attachments from a C# program without requiring the installer or the user to configure the program by specifying server details and email addresses etc.
(Mainly because they won't know the details, but also because they could change)
The program will normally be run as a service of a Windows Server, but can be run on a client.
I tried connecting to our own mail server and sending a email to myself, but some ISP's are blocking Port 25 on all servers but their own, so that method isn't working reliably.
Tried sending email through gmail but that was less successful as the port they used was blocked by firewalls. Ditto webservices connecting on weird ports.
Trying to use the local smptservice but did not work either.
It would be nice, but not essential if it was not dependant on my own Internet connection/Servers. (Don't mind them being delayed, but prefer them not to get lost).
Are there any webservices on http/https that allow you to do this sort of thing?
TIA
try using cdosys
http://support.microsoft.com/kb/310212
http://www.eggheadcafe.com/articles/20030316.asp
May have discovered the solution.
Was catching up on my blog reading over the weekend and came across a recent entry on Coding Horror and the very first comment mentions PostMarkApp which seems to do everything I need (and almost everything I want, apart from attachments which they are considering).

Creating an IMAP client application in Silverlight

I'd like to make a stripped down email client for my pre-schooler using Silverlight 3 and pulling email from a Gmail account.
I'll have some filters setup in Gmail so that only a subset of email is given a particular label, similar to creating a whitelist. Then, I'd like to pull those emails with that label to the Silverlight client. I'd like to avoid running any of the messages through the server (so that I can share this application with friends and not have their email app require a server).
I've never written any sort of email client (POP3 or IMAP) and am not sure if this will even be possible. Looking through the various libraries available for retrieving via IMAP, I can't find references to using a browser-limited client such as Silverlight.
Also, I'm guessing I'll be able to send via .NET built in SMTP objects in Silverlight, but haven't tested this yet either.
Can anyone point me in the right direction; tell me why this may or may not be feasible; or relate their own experiences regarding this type of challenge?
Silverlight does not yet allow arbitrary socket connections, which you would need to connect to an IMAP server on the privileged port of 143. Silverlight can only connect to servers, even with a client access policy file, on ports 4502-4534.
Your only options are to proxy to gmail via a server on those ports, or just do the IMAP work on the server and serve it down to the client app over HTTP.
Sorry about this-- enhanced socket support is always being looked at, but it has scary security implications and hasn't been implemented yet. Good luck finding a solution to your scenario.
There is a great example of a Silverlight based mail client here:
http://silvermail.com.au
I use this regularly to check my personal email from work, and I know that it works with GMail.
Hope that helps.

C#: Safely send bug report from a program

I would like my program to email me a bug-report when it fails. Is there any way of doing this... safely? I have found I can use System.Net.Mail MailMessage and SmtpClient and such, but of course, I will have to provide a username and a password to it (unless someone knows of one that doesn't need it?). And putting that in code I find a bit... I don't know. Technically it would mean that anyone could look at the source code or the compiled IL code (or what it was called) and find that username and password and use it for spamming or other not so good activites. Which is not very good!
Any ideas? Is there a better and/or different approach to this problem? Doesn't really have to be through email. But what I want is a way for the program to notify when something happens that I should fix. And to make that notification as little troublesome as possible to the user. Maybe even invisible (although a YesNo messagebox might be polite).
Anyone?
Instead of sending mail you could set up a web service that would receive the reports. The web service could run over https if you want to protect the data.
I did this for a customer once and it worked well.
The only problem is if the program is running somewhere without internet access.
Edit:
Don't tell this to anyone, but we even took a screenshot of the program when it crashed and posted it together with all information about the error that we could gather. It was incredibly useful!
You don't need to provide your password to email to yourself, as you don't need other people's password to send email to them.
You only need a password if you relay an email over a third party's SMTP server.
If your SMTP client connects right to example.com on port 25 and sends an email to test#example.com, no password is needed.
example.com above means an MX record, not an A record. This is a special type of record that holds the name of the server where all emails for example.com should go. There is no easy way to look it up from .NET, but if you are not going to change your SMTP server's address, you may hardcode it into SmtpClient.Host property.
To find out your mail server's address, type nslookup -q=MX example.com at your command prompt.
SMTP is not the best way to report errors, though. Home providers often block traffic on port 25 to all servers but their, to prevent spamming etc.
You better make a web server, create an instance of System.Net.WebClient in your program and send bug reports over HTTP. It's more reliable and you can easily use your client's proxy settings.
You can put the username & password in a web.config/app.config file. You can also encrypt the contents of your .config file (see here).
I do the same sort of thing and when our mail server moves to require authenticated SMTP, we plan to add exceptions for mail from certain addresses so that our automated processes don't need to provide credentials. If you're stuck with authenticated SMTP you'll need to work with your mail service provider to set up the same sort of exception or supply your credentials.

Sending mail without installing an SMTP server

I have a .Net application. I want this application to send an email to me. How do I implement this without installing an SMTP server?
Using an SmtpClient to send a MailMessage does not require you to have a server on your local machine.
Your e-mail service provider is the one with the server (e.g. smtp.gmail.com), and your SmtpClient talks to it.
This article by Peter Bromberg on eggheadcafe.com
C# SMTP Mail without SMTP Service or CDO
explains how to send email without relying on an SMTP client:
Sending email via TCP using the native
SMTP RFC commands "HELO", "MAIL From",
RCPT TO", etc. is no big deal. That's
one of the first tricks we learn with
Telnet. Finding or writing managed
code that will do so reliably is
another story. The code in the class
that follows is not my original code -
I've cobbled it together from three
different sample sources, fixing
namespaces, error handling, and other
minor items, changing console code to
class library code, and providing a
complete Winforms - based test harness
front end that illustrates its correct
usage.
I've also included sample code
to correctly process and add a mail
attachment via an OpenFileDialog here.
This code MIME encodes and transmits
the attachment(s) according to the
specification.
You can't send email without the services of a SMTP server, there is of course no need for you to install one, just point your code at your ISPs SMTP server or your companies Exchange server (or what ever they use).

Categories