1
votes

I am trying to send a test email from my IIS it has SMTP installed, but I am confused how to use IP address to send email. Here is my code

SmtpClient m = new SmtpClient();
m.Host = "xxx.xxx.xxx.xxx"; // my IP address.
m.Port = 25;
m.Send("xxx.xxx.xxx.xxx", "[email protected]", "Test", "This is a test email.....");

This code giving error

The specified string is not in the form required for an e-mail address.

UPDATE
I am new to email sending concept.

3
Your IP address will be automatically included in the e-mail headers, don't worry. However, if your purpose is to appear from a different IP address, this technique is called spoofing, and can be illegal in soume countries/activities - Mihalis Bagos
@Mihalis Bagos : No no I am not looking for spoofing. But my code giving error why? - Anderson

3 Answers

2
votes

According to MSDN, the first argument to Send() should be the From address. In emails, this is another email address. You're giving it an IP, not an email.

An IP address can be used as the hostname portion of an email address. For example:

[email protected]

(Though I doubt modern mail systems will like that, and many may flag it as spam or in some other way treat it as unwanted mail.) But it can not be used as the entire address.

0
votes

You need the from address:

m.Send("FROM EMAIL ADDRESS HERE", "[email protected]", "Test", "This is a test email.....");

Documentation Send(string, string, string, string)

Chances are you've received email from [email protected] with instructions

Do Not Reply to this Email

It seems like this would be your best bet, depending on if your mail server wants an authenticate address or not. For example, www.domainY.com, will only send domainY.com email address. There can be a lot of rules or no rules, but that can be for another time.

0
votes

The from address is whatever you want it to. I usually pick clever or descriptive names that describe the email that is being sent. Emails sent back to this address will end up in never land, however.

If you are using smtp you should have an smtp server such as server.domain.com or something of that nature.