In an application developed with Borland C++Builder 6, I am using TIdSMTP and TIdMessage to send email messages. Due to problems for external applications with the usual mail server in the configuration, I am defining the connection data through my Gmail account as follows:
Correo->From->Address = "******#******.org";
Correo->ReplyTo->EMailAddresses = "******#******.org";
Correo->From->Name = "*******";
Correo->Organization = "*******";
Enviar->Host = "smtp.gmail.com";
Enviar->Password = "******";
Enviar->Port = 465;
Enviar->Username = "******#gmail.com";
Enviar->UseTLS = utUseImplicitTLS;
SSLIOHandler->Port = 465;
SSLIOHandler->Host = "smtp.gmail.com";
SSLIOHandler->Destination = "smtp.gmail.com:" + IntToStr(SSLIOHandler->Port);
SSLIOHandler->SSLOptions->Method = sslvTLSv1_2;
SSLIOHandler->SSLOptions->Mode = sslmUnassigned;
The emails are sent without any problem, but I am checking that in addition to the copies that I send one to my Gmail address. I have verified that the Gmail address appears in the message headers in the Return-Path field.
I have been looking and, at least in Indy 10 for BCB 6, I have not found how to modify that field. How can I get copies to only reach the address indicated in the ReplyTo field of TIdMessage?
The TIdMessage.ReplyTo property has no effect on the Return-Path header. The ReplyTo is only used for the Reply-To header, which recipients use to reply back to the sender. The Reply-To header is not used by the receiving SMTP server at all.
The Return-Path header is generated by the receiving SMTP server using the address specified in the sending client's SMTP MAIL FROM command. You can specify that address in the TIdMessage.Sender and TIdMessage.From properties (in that order), or by using one of the other overloaded TIdSMTP.Send() methods that has an AFrom parameter.
Related
My main goal is to to get VIN no of my control unit but for that i need to send command to controller and before sending any command to controller i must have to claim address.
I have send below command on my network but didn't got any response from it.
Msg.id.pdu_bit.edp = 0;
Msg.id.pdu_bit.dp = 0;
Msg.id.pdu_bit.pf = 234;
Msg.id.pdu_bit.ps = 255;
Msg.id.pdu_bit.sa = 249;
Msg.id.pdu_bit.pri = 6;
Msg.buf[0] = 0x00; //LSB First
Msg.buf[1] = 0xEE; // pgn for claim address
Msg.buf[2] = 0x00;
Msg.len = 3;
Is this is right way to claim address or do i have send different command??
It looks like you have some confusion between PGN 60928 (address claim) and PGN 59904 (request PGN)
Msg.id.pdu_bit.pf = 234;
Needs to be
Msg.id.pdu_bit.pf = 238;
The PGN for address claim is 60928 so your PF field in your J1939 header needs to be 238 (0xEE). Your data is going to be application specific although it's data length should be 8. See J1939 Spec slide 41 for more information on this data format.
Alternatively if you use PGN 59904, THAT is when your data length is 3 (unless you have more application specific information) and your data is the PGN that you want to request.
You do not have to request an address claim PGN, you just simply send out the address claim with your source address set to the address you want to claim.
I have a problem when I upload an application to the Web. I want to send a mail to several users but it doesn't work, but when I send in localhost work properly.
Here's my code to send the mail
System.Net.Mail.MailMessage correo = new System.Net.Mail.MailMessage();
correo.To.Add(mail_usuario);
correo.Body = cuerpomensaje;
correo.BodyEncoding = System.Text.Encoding.UTF8;
correo.Priority = System.Net.Mail.MailPriority.Normal;
correo.IsBodyHtml = true;//false tested too.
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
smtp.Host = "mail.cscdecision.com";
smtp.Credentials = new System.Net.NetworkCredential("id#domain.com", "IDPass");
//smtp.Credentials = new System.Net.NetworkCredential(sMailEnvioEmpresaServicio , sClaveEmpresaServicio);
smtp.EnableSsl = true;
smtp.SendAsync(correo, null);
//smtp.Send(correo);
The error is: "Unable to send to all recipients"
Why in the localhost works and in the host No?
Error: System.Net.Mail.SmtpFailedRecipientsException: Unable to send to all recipients.
System.Net.Mail.SmtpFailedRecipientException: The mailbox is unavailable.
The server response was: 5.7.1 <csc#cscdecision.com> Access to <ccruz#decision.com.ec> not allowed
have you specified what port the mail server is on?
i.e smtp.port = 25 (or a different port for SSL)
it's possible your host is blocking the port you are using.
Are you sending to same domain name .? If yes so you have to configure that this domain has a remote mail server not localy .
This is common in cpanel hosts .when the domain has a remote mail server
I'm trying to send email using asp.net mvc application. Smtp client is configured in web.config e.g.:
<mailSettings>
<smtp from="noreply#test.sk">
<network host="mail.test.sk" defaultCredentials="false" userName="noreply#test.sk" password="pass" port="25"/>
</smtp>
</mailSettings>
C#:
using (SmtpClient client = new SmtpClient())
{
MailMessage message = new MailMessage(from, to, subject, body);
client.Timeout = 10000;
client.Send(message);
return false;
}
The thing is, it doesn't work (I get timeout exception) until I try to send email using outlook. Right after sending email by outlook it successfully sends it also by my web application. Is there some special kind of authentication which outlook is doing which then allows all emails from my IP to be authenticated?? What is the reason it works only after sending it by outlook?
BTW:
I'm running the application in VS asp.net development server. When I deploy it to webhosting server, it doesn't work (timeout).
My webhosting provider told me there is a classic smtp authentication on that server (not pop3 before smtp).
EDITED:
I figured out, when it worked and I tried it by telnet or traced it by wireshark, the communication started by:
220 mail2.hostmaster.sk ESMTP Postfix
EHLO fernet-PC
250-mail2.hostmaster.sk
250-PIPELINING
250-SIZE 104857600
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
...
Compared to when it didn't work (just tried a day before), the whole communication looked like:
220-mail2.hostmaster.sk ESMTP Postfix
EHLO fernet-PC
250-mail2.hostmaster.sk
250-SIZE 104857600
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
So there is a difference in supported auth methods and support for pipelining. I guess that System.Net.Mail.SmtpClient then doesn't know which authentication method should it use and so it stucks and therefore I'm getting the timeout exception.
That's interesting that outlook has no problems to connect and send email.
I solved my problem by not using their smtp server, as I'm running out of time. I'm using gmail's smtp server instead. I created new gmail account where I set alias to what I needed, so the email looks like it didn't come from gmail on the first look.
I have fixed a similar problem on a site and came across this Question while researching the issue.
The code below works for Google Apps for Business;
public class SendSMTPEmail
{
public static void SendText(string ToName, string ToEmail, string FromName, string FromEmail, string Subject, string Content)
{
MailAddress from = new MailAddress(ToEmail, ToName);
MailAddress to = new MailAddress(ToEmail, ToName);
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential("username#googlemail.com", "yourpassword"),
Timeout = 20000
};
MailMessage message = new MailMessage()
{
From = from,
Body = Content,
Subject = Subject
};
message.To.Add(to);
smtp.Send(message);
}
}
Does this help?
I currently have an application written that generates pdf vouchers and emails to their perspective recipients. However the function I use is client dependent (MS Outlook) and I would really like to make this email client agnostic as we have many customers and not all of them use Outlook.
I have looked at a few options but can't really find anything in searching that seems to solve my problem.
Does anyone know a good way to send email using the customers smtp connection regardless of the client and send an attachment with it without calling the client directly to do it?
Or you can use the Synapse library, for sending a mail using SMTP, ideally in its newest snapshot.
Here is the code which should send the mail with attached c:\voucher.pdf file from sender#from.com to recipient#to.com to the smtp.server.com with login login and password password. About the rest of the functions from the TMimeMess class I would refer you directly to the reference.
I hope this will work because I've simplified and localized much more complicated code I'm using and I can't verify it nor compile. If not, let's downvote it :)
uses
SMTPSend, MIMEPart, MIMEMess;
procedure TForm.SendEmailClick(Sender: TObject);
var
MIMEText: TStrings;
MIMEPart: TMimePart;
MIMEMessage: TMimeMess;
begin
MIMEText := TStringList.Create;
MIMEText.Add('Hello,');
MIMEText.Add('here is the text of your e-mail message,');
MIMEText.Add('if you want the HTML format, use AddPartHTML');
MIMEText.Add('or e.g. AddPartHTMLFromFile if you have your');
MIMEText.Add('HTML message content in a file.');
MIMEMessage := TMimeMess.Create;
with MIMEMessage do
try
Header.Date := Now;
Header.From := 'sender#from.com';
Header.ToList.Clear;
Header.ToList.Add('recipient#to.com');
Header.CcList.Clear;
Header.Subject := 'E-mail subject';
Header.XMailer := 'My mail client name';
MIMEPart := AddPartMultipart('mixed', nil);
AddPartText(MIMEText, MIMEPart);
AddPartBinaryFromFile('c:\voucher.pdf', MIMEPart);
EncodeMessage;
if SendToRaw(Header.From, // e-mail sender
Header.ToList.CommaText, // comma delimited recipient list
'smtp.server.com', // SMTP server
Lines, // MIME message data
'login', // server authentication
'password') // server authentication
then
ShowMessage('E-mail has been successfuly sent :)')
else
ShowMessage('E-mail sending failed :(');
finally
Free;
MIMEText.Free;
end;
end;
Update:
According to nice comment from Downvoter step into the light (man, change your nick please, it's not cool anymore :), would be really bad if you will send the list of all recipients to everyone. With synapse you cannot add BCCs to the message header; there's no Header.BCCList property in MIMEMessage.
Instead you can directly modify the data before sending them.
// First, you will remove the line where you are adding a recipient to the list
Header.ToList.Add('recipient#to.com');
// the rest between you can keep as it is and after the message encoding
EncodeMessage;
// and before sending the mail you'll insert the line with BCCs
Lines.Insert(1, 'Bcc: jane#invisiblecustomer.com, lisa#invisiblecustomer.com');
if SendToRaw ...
You could use Indy as your SMTP client, independent of the system default e-mail client. Here's a basic demo of sending e-mails without attachments, and there are detailed articles here and here about sending HTML or plain-text e-mails and with or without attachments.
If you want to integrate with the existent email client (e.g. see the sent messages in the sent, sent items, etc. folder of the email client), you could use Simple MAPI. The headers are translated in the Mapi unit in Delphi (at least in D2007).
But be careful to check if the actual client supports Simple MAPI.
Since the demo given in http://www.indyproject.org/Sockets/Demos/index.EN.aspx only saves the received stream to a file, I don't know how to effectevely send that stream as a mail.
Could anyone teach me how to do this or to point me some more complete example?
Here's a complete example on how to send an email:
VAR SMTP : TIdSMTP;
VAR MSG : TIdMSG;
.
.
MSG:=TIdMSG.Create(NIL);
TRY
WITH MSG.Recipients.Add DO BEGIN
Name:='<Name of recipient>';
Address:='<Email address of recipient>'
END;
MSG.BccList.Add.Address:='<Email address of Blind Copy recipient>';
MSG.From.Name:='<Name of sender>';
MSG.From.Address:='<Email address of sender>';
MSG.Body.Text:='<Message Body>';
MSG.Subject:='<Subject of message>';
SMTP:=TIdSMTP.Create(NIL);
TRY
SMTP.Host:='x.x.x.x'; // IP Address of SMTP server
SMTP.Port:=25; // Port address of SMTP service (usually 25)
SMTP.Connect;
TRY
SMTP.Send(MSG)
FINALLY
SMTP.Disconnect
END
FINALLY
SMTP.Free
END
FINALLY
MSG.Free
END;
.
.
(I know that WITH is frowned upon, but I generally use it in instances like this where there's no doubt as to what is going on, and where there's no (or just an infinitesimal) chance of ambiguity)
A SMTP server component can't send mail - it can only receive it. You need a SMTP client component (TidSMTP) to send mail. A mail server when it sends mail acts like an SMTP client.