需要发送邮件到Extrnal邮件ID而不具有内部邮件ID [英] Need to send mail to Extrnal mail ids without having the Internal mail id
问题描述
我面临非常混乱的问题。
I am facing very confusing problem.
在我的网站上,所有用户都有自己的邮箱,当他们登录时可以看到他们的邮箱。
In my website all user have there own mail box which can be seen by them when they log in.
我没有分配任何像123@gmail.com或其他任何ID这样的id。
I have not assigned then any ids like 123@gmail.com or anything else.
他们可以发送邮件到每个 -
They can send mails to each-other through their names only.
当他们向不同的用户发送邮件时,它将通过personid的帮助保存在数据库中。
When they send a mail to diffrent user, it is saved as a data row in the database with the help of personid.
现在我想要的是,如果用户发送邮件给其他用户,它也应该自动发送通知邮件到接收方的外部邮件ID。
Now i want that if a user sends a mail to one other user, it should also automatically send a notification mail to the receiver's external mail id.
我发现相关代码如
MailMessage mail = new MailMessage();
mail.To.Add("hiral@yahoo.com");
mail.From = new MailAddress("hiral@gmail.com");
mail.Subject = "Send Email by asp.net code using google or gmail smtp server";
string Body = "Hi, I am testing Email function in asp.net";
mail.Body = Body;
SmtpClient smtp = new SmtpClient("localhost", 25);
smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
smtp.Credentials = new System.Net.NetworkCredential
("hiral@gmail.com", "xxxxxxxxxxxxxx");
//Or your Smtp Email ID and Password
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.EnableSsl = true;
smtp.Send(mail);
lblsuccess.Visible = true;
现在正在为我工作。
It is working perfectly for me now..
现在我需要更改
mail.From = new MailAddress("hiral@gmail.com");
因为它可以是任何没有这样的电子邮件ID的用户。
Because it can be any user without any email id like this.
我可以为此做什么?
推荐答案
从数据库中检索个人/发件人信息personid然后把它放在变量列表上。
Retrieve the person/sender information from database by personid then put it on a variable list.
private class senderInformation{
private string lastname;
private string firstname;
private string email;
}
senderInformation person = new senderInformation();
person.lastname = "Smith";
person.firstname = "John";
person.email= "john@gmail.com";
mail.From = new MailAddress(person.email.toString());
这篇关于需要发送邮件到Extrnal邮件ID而不具有内部邮件ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!