how to send mail via AUTHENTICATED smtp account?

Discussion in 'ASP .Net' started by RN, Feb 22, 2005.

  1. RN

    RN Guest

    I am tired of sending mail from the built-in SMTP service for so many
    reasons (errors are nondescriptive in the event log, it doesn't let me
    control which IP address it sends from, and it identifies itself as the
    computer name which is not in domain.com format, triggering spam filter
    problems).

    Instead, I want to have my code send through an SMTP server of a company
    that we pay for mail service. But they require a username and password.
    How do I use something other than "localhost" for the Smtp Server and how do
    I pass the username and password?
    RN, Feb 22, 2005
    #1
    1. Advertising

  2. RN

    Smithers Guest

    I recently hunted high and low for the same purpose. Here is what I found.
    It is apparently undocumented, but has been working for me very well. The
    whole trick is in the mail.Fields.Add lines:

    System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
    mail.To = eMailRecipients; //";";
    mail.From = "";
    mail.Subject = "Hello World!";
    mail.Body = messageToGo;
    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",
    "1"); //basic authentication
    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",
    "MyFullUserNameHere"); //set your username here
    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",
    "MyPasswordHere"); //set your password here

    System.Web.Mail.SmtpMail.SmtpServer = "Mail.YourDomain.com"; //your smtp
    server goes here
    System.Web.Mail.SmtpMail.Send( mail );

    If someone else has a better way I'd like to know.

    -Smithers



    "RN" <> wrote in message
    news:JuOSd.23051$...
    >I am tired of sending mail from the built-in SMTP service for so many
    > reasons (errors are nondescriptive in the event log, it doesn't let me
    > control which IP address it sends from, and it identifies itself as the
    > computer name which is not in domain.com format, triggering spam filter
    > problems).
    >
    > Instead, I want to have my code send through an SMTP server of a company
    > that we pay for mail service. But they require a username and password.
    > How do I use something other than "localhost" for the Smtp Server and how
    > do
    > I pass the username and password?
    >
    >
    Smithers, Feb 22, 2005
    #2
    1. Advertising

  3. RN

    RN Guest

    Thanks, I'm excited to try it.

    Maybe you also know the answer to this very related question... Sometimes I
    send from aliases that are mapped on the POP3 server if someone did reply.
    For example, suppose I have a real account called , and
    that's a real account that has a username and password that I can use in
    your example. But often I will send mail from something else like
    . There's no account for this, but I have an
    alias on the pop server that will map any incoming mail to order-receipts
    over to the real sales account. Obviously I still need to send from
    order-receipts, though. Using the SMTP server with IIS, this works fine.
    Now that I'm going to send through a 3rd party mail server, I'm wondering
    what will happen. Can I put anything I want in the mail.From field as long
    as it is at the same domain?

    Have you found out anything else, good or bad, about using this technique
    compared to the regular IIS SMTP service?

    Again, thanks very much. Yours was a perfect newsgroup reply!


    "Smithers" <> wrote in message
    news:...
    > I recently hunted high and low for the same purpose. Here is what I found.
    > It is apparently undocumented, but has been working for me very well. The
    > whole trick is in the mail.Fields.Add lines:
    >
    > System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
    > mail.To = eMailRecipients; //";";
    > mail.From = "";
    > mail.Subject = "Hello World!";
    > mail.Body = messageToGo;
    >

    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenti
    cate",
    > "1"); //basic authentication
    >

    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername
    ",
    > "MyFullUserNameHere"); //set your username here
    >

    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword
    ",
    > "MyPasswordHere"); //set your password here
    >
    > System.Web.Mail.SmtpMail.SmtpServer = "Mail.YourDomain.com"; //your smtp
    > server goes here
    > System.Web.Mail.SmtpMail.Send( mail );
    >
    > If someone else has a better way I'd like to know.
    >
    > -Smithers
    >
    >
    >
    > "RN" <> wrote in message
    > news:JuOSd.23051$...
    > >I am tired of sending mail from the built-in SMTP service for so many
    > > reasons (errors are nondescriptive in the event log, it doesn't let me
    > > control which IP address it sends from, and it identifies itself as the
    > > computer name which is not in domain.com format, triggering spam filter
    > > problems).
    > >
    > > Instead, I want to have my code send through an SMTP server of a company
    > > that we pay for mail service. But they require a username and password.
    > > How do I use something other than "localhost" for the Smtp Server and

    how
    > > do
    > > I pass the username and password?
    > >
    > >

    >
    >
    RN, Feb 23, 2005
    #3
  4. RN

    Smithers Guest

    <<Yours was a perfect newsgroup reply>>
    Is that like a "great golf shot?" (what other type of shot is there on a
    golf course?)

    <<Can I put anything I want in the mail.From field as long as it is at the
    same domain?>>
    AFAIK you can put anything you want in the mail.From field... doesn't even
    have to be in the same domain. You could put "snoop@dog" in there if you
    wanted to.

    <<Now that I'm going to send through a 3rd party mail server, I'm wondering
    what will happen>>
    Your mail will go through as expected... as long as you use credentials that
    are valid on the 3rd party mail server.

    <<Have you found out anything else, good or bad>>
    Nope - it works and that's as far as I got. I have work to do so I didn't
    sit down and simultaneously try multiple approaches for the fun of it.

    I'd like to hear from any others if they have any better way to do the same
    thing *without* using CDO or some other mail component. It does

    Those were great newsgroup questions!

    HTH!


    "RN" <> wrote in message
    news:j3SSd.23239$...
    > Thanks, I'm excited to try it.
    >
    > Maybe you also know the answer to this very related question... Sometimes
    > I
    > send from aliases that are mapped on the POP3 server if someone did reply.
    > For example, suppose I have a real account called , and
    > that's a real account that has a username and password that I can use in
    > your example. But often I will send mail from something else like
    > . There's no account for this, but I have an
    > alias on the pop server that will map any incoming mail to order-receipts
    > over to the real sales account. Obviously I still need to send from
    > order-receipts, though. Using the SMTP server with IIS, this works fine.
    > Now that I'm going to send through a 3rd party mail server, I'm wondering
    > what will happen. Can I put anything I want in the mail.From field as
    > long
    > as it is at the same domain?
    >
    > Have you found out anything else, good or bad, about using this technique
    > compared to the regular IIS SMTP service?
    >
    > Again, thanks very much. Yours was a perfect newsgroup reply!
    >
    >
    > "Smithers" <> wrote in message
    > news:...
    >> I recently hunted high and low for the same purpose. Here is what I
    >> found.
    >> It is apparently undocumented, but has been working for me very well. The
    >> whole trick is in the mail.Fields.Add lines:
    >>
    >> System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
    >> mail.To = eMailRecipients; //";";
    >> mail.From = "";
    >> mail.Subject = "Hello World!";
    >> mail.Body = messageToGo;
    >>

    > mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenti
    > cate",
    >> "1"); //basic authentication
    >>

    > mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername
    > ",
    >> "MyFullUserNameHere"); //set your username here
    >>

    > mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword
    > ",
    >> "MyPasswordHere"); //set your password here
    >>
    >> System.Web.Mail.SmtpMail.SmtpServer = "Mail.YourDomain.com"; //your smtp
    >> server goes here
    >> System.Web.Mail.SmtpMail.Send( mail );
    >>
    >> If someone else has a better way I'd like to know.
    >>
    >> -Smithers
    >>
    >>
    >>
    >> "RN" <> wrote in message
    >> news:JuOSd.23051$...
    >> >I am tired of sending mail from the built-in SMTP service for so many
    >> > reasons (errors are nondescriptive in the event log, it doesn't let me
    >> > control which IP address it sends from, and it identifies itself as the
    >> > computer name which is not in domain.com format, triggering spam filter
    >> > problems).
    >> >
    >> > Instead, I want to have my code send through an SMTP server of a
    >> > company
    >> > that we pay for mail service. But they require a username and
    >> > password.
    >> > How do I use something other than "localhost" for the Smtp Server and

    > how
    >> > do
    >> > I pass the username and password?
    >> >
    >> >

    >>
    >>

    >
    >
    Smithers, Feb 23, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VHVzaGFy?=

    how to send authenticated mail using ASP.NET 2

    =?Utf-8?B?VHVzaGFy?=, Jun 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    373
    =?Utf-8?B?VHVzaGFy?=
    Jun 12, 2005
  2. Replies:
    15
    Views:
    155,884
    abhishek-technicalwork
    Jul 11, 2012
  3. Abhijit
    Replies:
    0
    Views:
    151
    Abhijit
    Apr 12, 2004
  4. Asfand Yar Qazi
    Replies:
    2
    Views:
    198
    Asfand Yar Qazi
    Feb 13, 2005
  5. Maneesh
    Replies:
    1
    Views:
    91
    Ben Morrow
    May 16, 2006
Loading...

Share This Page