Question

send mail using smtp in c#

Asked by: dave_kny

is there anyway to send mail using yahoo or hotmail or others mail server?
here my code,

System.Web.Mail.MailMessage message=new System.Web.Mail.MailMessage();
                  message.From="xxx@yahoo.com" ;
                  message.To="xx@yahoo.com" ;
                  message.Subject="ddddd";
                  message.BodyFormat = MailFormat.Text;
                  message.Body="yyyyy"
                  
                  message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver","smtp.mail.yahoo.com");
                  message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport",25);
                  message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing",2);
                  message.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",1 );
                  message.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendusername","username");
                  message.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword","password");
                  System.Web.Mail.SmtpMail.SmtpServer="smtp.mail.yahoo.com";

but its can't work...
anything wrong with my code?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-05-09 at 21:30:31ID21418431
Tags

send

,

mail

,

smtp

Topic

C# Programming Language

Participating Experts
6
Points
100
Comments
24

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. cfmail smtpserver problem
    hai, everyone! i had a problem in using CFMail. if use CFmail, the smtpserver is a required field. let say my customer can log into my server, and they had their particulars including e-mail. once they want to mail to me, i plan to use cfmail. but for cfmail, it needs the sm...
  2. Sending E-mail using CDO
    First off, I know there are tons of threads about this subject here on EE. However, I need some experts to walk me through this. I want to use CDO so I don't get Outlook messages asking if it's ok to allow a program to send a message. Anyway, I switch to a new domain in my...
  3. CDO error
    Hi, I'm using this code to send e-mails using company's smtp, it gives me an error "The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server was not available." Any ideas? objEmail.Configuration.Fields.Item("ht...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: cyberdevil67Posted on 2005-05-09 at 21:37:08ID: 13965458

Hi dave_kny,

 when sending mail you still need to use your ISP for that, this is usually blocked by ISP's because of spam. So you could receive via that server, but to send via that server is considered BAD and is usually blocked to stop people from sending mail through their servers.


Cheers!

 

by: harwantgrewalPosted on 2005-05-09 at 22:09:52ID: 13965576

 

by: harwantgrewalPosted on 2005-05-09 at 22:13:09ID: 13965593

And this too This will sure help yo

http://blogs.wdevs.com/qc/archive/2005/01/14/1951.aspx

Harry

 

by: cyberdevil67Posted on 2005-05-09 at 22:17:15ID: 13965607

Yes you can not use the smtp server of another mail server when you are not connected to that server directly.

System.Web.Mail.SmtpMail.SmtpServer="smtp.mail.yahoo.com";

Need to point to your mail server..

 

by: harwantgrewalPosted on 2005-05-09 at 22:22:59ID: 13965628

I guess this shouldt be true as I can configure my OUTLOOK to any smtp server on my ISP if I have smtp access to that provider. For example yahoo smtp service is paid service and if I am a paid member I can configure my OUTLOOK to yahoo. Gmail is free service and the second URL gives the example for gmail. So I guess its not true that ISP is blocked if one can Access that email from the same ISP through OUTLOOK

Harry

 

by: cyberdevil67Posted on 2005-05-09 at 22:28:03ID: 13965644

Actually no...

I have a work account and a normal ISP account, and if I need to send email to my work account I need to send it via my ISP account.

These as I said are blocked, because Mail Relaying is not allowed.

 

by: harwantgrewalPosted on 2005-05-09 at 22:36:04ID: 13965675

That means if you want to send email to any email address you have to sent it via your ISP? Like I have an ISP account and I am using gmail to send email without any issues from OUTLOOK. If you are talking about relay let me explain a little here. I am ISP I have smtp installed I made configuration that only IP of my range can relay the email if they are using my SMTP, but in case of gmail or yahoo you are using their SMTP and they relay message for authenticated users. The only case you can not send your email from OUTLOOK if that port/URL is blocked and again that is a Firewall configuration not Relay configuration. So one can check by configuring the OUTLOOK.
Thanks

Harry

 

by: cyberdevil67Posted on 2005-05-09 at 22:45:58ID: 13965709

Define Authenticated.

If you are ISP then you will know the answer to your question. As I said I am authenticated with my work account and my ISP account. And when I am at home and wish to send an email via my work account I HAVE TO SEND IT via my ISP account.

So if yahoo, hotmail, gmail allowed this could you imagine the spam that would be sent via these accounts, how do they authenticate you if you do not log into there servers.

As I have written my own mail server I know what I am talking about.

 

by: harwantgrewalPosted on 2005-05-09 at 23:23:09ID: 13965822

Thats very nice that you have written your own mail server. I havnt that much experience, may be what I am trying to communicate is not proper. Can we talk with example. I have a ISP account I am authenticated with ISP now I want to send email via my work account isnt it that I have to be authenticated with SMTP not with ISP? the username and password of my work SMTP is provided then where ISP play now?

Harry

 

by: cyberdevil67Posted on 2005-05-09 at 23:32:29ID: 13965852

NO, NO, NO

YOU CAN NOT CONNECT TO ANOTHER SMTP SERVER through an ISP that does not allow mail relay, and mail relay's are normally disallowed.

Now because you do not have a direct connection to you work account mail server, yahoo, hotmail account you can not relay mail and HAVE to use your ISP's smtp mail server.

 

by: cyberdevil67Posted on 2005-05-09 at 23:33:40ID: 13965858

We set clients up all the time and they can not understand why they have to use their ISP for sending mail, when we explain to them that if this was allowed the world would be full of spam they tend to understand.

And yes we are a sort of ISP for mail to our clients.

 

by: harwantgrewalPosted on 2005-05-09 at 23:36:30ID: 13965867

Okay that means you are saying if I send a email from my home it goes to SMTP ISP and replayed to gmail and then gmail authenticate the user and send email? if ISP has blocked reply to gmail then it wont go?

 

by: cyberdevil67Posted on 2005-05-10 at 00:06:23ID: 13965986

No,

You can send via your ISP smtp server, as you are already authenticated when you logged on to your ISP.

However if you want to connect to gmail, you need to know the server name, the port name, and the password for the account to do this. You can not just use a normal smtp account, if you want to do this you need to use your ISP.

 

by: harwantgrewalPosted on 2005-05-10 at 02:28:20ID: 13966602

oh BOY sorry to say that I guess you dont know that gmail gives that, thats why I was wondering why you are saying to use your ISP smtp. If you look into gmail and yahoo they provide all the information the URL port and username and password to authenticate. Thats how the code is working.

 

by: cyberdevil67Posted on 2005-05-10 at 03:05:48ID: 13966741

No I do know that...

If you want to use the standard port 25, I not sure the port gmail uses put I know its not 25.

 

by: harwantgrewalPosted on 2005-05-10 at 03:43:56ID: 13966925

Yes its not 25 and its over the SSL its // - smtp.gmail.com use port 465 or 587

 

by: sun4sundayPosted on 2005-05-10 at 04:29:03ID: 13967182

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("luckyperson@online.microsoft.com");
message.Subject = "This is the Subject line";
message.From = new System.Net.Mail.MailAddress("From@online.microsoft.com");
message.Body = "This is the message body";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("yoursmtphost");
smtp.Send(message);


check here for more details
http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=651


this shows a simpe application to send mails
http://www.codeproject.com/csharp/sendmailcsharp.asp

sun4sunday



 

by: thoffmanPosted on 2005-05-12 at 12:45:01ID: 13990277

While it is true that most SMTP servers prevent relaying, not all of them do. While is is true that many ISPs block port 25 for outgoing SMTP, again, not all ISPs block it.

The best thing to do is try an app like Outlook. If you can get Outlook sending email to the target server through your ISP, then nothing is blocked, and there is a problem in your code that is preventing it. On the other hand, if you can't get Outlook to send it, there's no point in trying to debug your code, since it will also fail.

--
Troy

 

by: axawirePosted on 2005-05-12 at 21:00:01ID: 13993216

hi, i dont know if this will help you but...

I think its 99% prob that your isp is blocking you from connecting to "smtp.mail.yahoo.com" on port 25

your code:
  message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver","smtp.mail.yahoo.com");
  message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport",25);

so...
yahoo offers another port if this is the case, port 587
  message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport",587);

second yahoo states that if your "from" field is not the email address associated with the "username" and "password" it will not send the email.

so
  message.From="xxx@yahoo.com" ; //has to actually be a vaild email that belongs with the "username" and "password"

but you were probably just hiding the account information anyway...

good luck, post if it works out for you, im trying to do something along the same lines

 

by: axawirePosted on 2005-05-13 at 00:12:26ID: 13993709

ok, i found this code that i (converted to vb.net because thats what i am using) successfully sent an email to my home accout from google using there smtp server code.  The original code was in c# and is soley thanks to http://blogs.wdevs.com/qc/archive/2005/01/14/1951.aspx

public string sendMail (string from, string to, string cc, string bcc, string subject, string body) {
 // Mail initialization MailMessage mail = new MailMessage();
 mail.From = from;
 mail.To = to;
 mail.Cc = cc;
 mail.Bcc = bcc;
 mail.Subject = subject;
 mail.BodyFormat = MailFormat.Text;
 mail.Body = body;
 // Smtp configuration
 SmtpMail.SmtpServer = "smtp.gmail.com";
 // - smtp.gmail.com use smtp authentication
 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "myemail@gmail.com");
 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "mypassword");
 // - smtp.gmail.com use port 465 or 587
 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465");
 // - smtp.gmail.com use STARTTLS (some clients call this SSL)
 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
 // Mail sending
 try {
   SmtpMail.Send(mail);
   return "";
 } catch (Exception ex) {
   return ex.Message;
}

 

by: axawirePosted on 2005-05-13 at 06:58:37ID: 13995868

lol, if i had actually read the other responses before i posted i would know harwantgrewal already solved the prob way back when.

 

by: dave_knyPosted on 2005-05-17 at 19:23:12ID: 14024052

Thanks for active reply from harwantgrewal,axawire and cyberdevil67.
i try all the solution u all provide and found that using the gmail smtp is works..

 

by: markwaugh365Posted on 2005-09-28 at 12:06:08ID: 14977984

i heard that due to gmail modifications, this may not be possible, can anyone verify that this still works, just wondering if its possible anymore.

 

by: dave_knyPosted on 2005-09-28 at 20:55:33ID: 14980860

markwaugh365,
i try this code and not working anymore
do you know wat modification they do? any other way to send mail using other smtp mail server?

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...